【Reading Note】Python读书杂记
赋值
>>> list=[]
>>> app=[list,list,list]
>>> app
[[], [], []]
>>> app[1].append(1)
>>> app
[[1], [1], [1]]
>>> id(app[1])
1666670423944
>>> id(app[2])
1666670423944
条件语句:
>>> app=[1,'',"cat",[]]
>>> for i in app:
print(app[i])
>>> for i in app:
print(i) 1 cat
[]
>>> for i in app:
if i:
print(i) 1
cat
>>> [i for i in app]
[1, '', 'cat', []]
>>> [i for i in app if i]
[1, 'cat']
any和all
>>> any(w!=0 for w in app)
True
>>> all(w!='' for w in app)
False
元组:
>>> t='ass',33,''
>>> t
('ass', 33, '')
各种遍历序列的方式
>>> s
(2, 5, 3, 1, 6, 7, 95, 3)
>>> [n for n in s]
[2, 5, 3, 1, 6, 7, 95, 3]
>>> [n for n in sorted(s)]
[1, 2, 3, 3, 5, 6, 7, 95]
>>> [n for n in set(s)]
[1, 2, 3, 5, 6, 7, 95]
>>> [n for n in reversed(s)]
[3, 95, 7, 6, 1, 3, 5, 2]
>>> [n for n in s[::-1]]
[3, 95, 7, 6, 1, 3, 5, 2]
>>> [n for n in set(s).difference(t)]
[1, 2, 3, 5, 6, 7, 95]
>>> t=[1,23,4,5]
>>> [n for n in set(s).difference(t)]
[2, 3, 6, 7, 95]
>>> [n for n in random.shuffle(s)]
训练集和测试集语料划分:9:1
>>> text=open(r"C:\Users\BNC-PC\Desktop\text.txt","r").read()
>>> len(text)
34176
>>> cut=int(0.9*len(text))
>>> training_data,test_data=text[:cut],text[cut:]
>>> len(training_data)
30758
>>> len(test_data)
3418
>>> text == training_data + test_data
True
>>> len(training_data)/len(test_data)
8.998829724985372
>>>
合并
>>> words='我 是 中国 人 , 我 爱 祖国'.split()
>>> worelen=[w for w in words]
>>> worelen
['我', '是', '中国', '人', ',', '我', '爱', '祖国']
>>> '='.join(w for w in worelen)
'我=是=中国=人=,=我=爱=祖国'
函数:
def bncsum(m,n):
sum=0
if n:
sum=m/n
else:
sum=n
print(sum) >>> bncsum(4,5)
0.8
>>> bncsum(4,0)
0
>>> help(bncsum)
Help on function bncsum in module __main__: bncsum(m, n)
【Reading Note】Python读书杂记的更多相关文章
- Web Scraping with Python读书笔记及思考
Web Scraping with Python读书笔记 标签(空格分隔): web scraping ,python 做数据抓取一定一定要明确:抓取\解析数据不是目的,目的是对数据的利用 一般的数据 ...
- 【Reading Note】算法读书杂记
1 排序 排序基本信息 稳定性:排序前大的数在排序后,大的数依然保持不变就是稳定排序,反之不稳定 内外排序:根据待排序的记录是否放在内存里面区分的.诸如:插入排序(直接插入&希尔).交换排序( ...
- Python Geospatial Development reading note(1)
chapter 1, Summary: In this chapter, we briefly introduced the Python programming language and the m ...
- Python学习杂记
Python中关键字yield有什么作用? 首先得理解generators,而理解generators前还要理解iterables: 你可以用在for...in...语句中的都是可迭代的:比如list ...
- python初学杂记
python常用命令: 1.python 或者 python3 打开交互式python解释器 2.python hello.py 通过命令提示符运行python脚本 交互式python解释器常用 ...
- Python 读书系列
1. 原文<A byte of Python> 翻译版:<<简明Python教程>> 2. Python:核心编程
- OK - A byte of python - 读书笔记
看这本书的目的:再熟悉基本概念. 大部分都是知道,但是需要 明确 出来的 概念. - 欢迎吐槽错误,非常感谢. <A byte of python> - THIS 1. 组织行 - 形式: ...
- 流畅的Python读书笔记(二)
2.1 可变序列与不可变序列 可变序列 list. bytearray. array.array. collections.deque 和 memoryview. 不可变序列 tuple. str 和 ...
- Reading | 《Python基础教程》第1次阅读
目录 一.基础知识 1.数和表达式 浮点除法和整数除法 负数整除和取余 圆整 乘方运算 2.变量名 3.获取用户输入 4.模块 5.让脚本像普通程序一样 6.字符串 单.双引号 引号的转义 字符串拼接 ...
随机推荐
- 我们是怎么做Code Review的
前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...
- LeetCode-3LongestSubstringWithoutRepeatingCharacters(C#)
# 题目 3. Longest Substring Without Repeating Characters Given a string, find the length of the longes ...
- TODO:Laravel 内置简单登录
TODO:Laravel 内置简单登录 1. 激活Laravel的Auth系统Laravel 利用 PHP 的新特性 trait 内置了非常完善好用的简单用户登录注册功能,适合一些不需要复杂用户权限管 ...
- TODO:macOS上ThinkPHP5和Semantic-UI集成
TODO:macOS上ThinkPHP5和Semantic-UI集成 1. 全局安装 (on OSX via homebrew)Composer 是 homebrew-php 项目的一部分 2. 把X ...
- Linux scp 设置nohup后台运行
Linux scp 设置nohup后台运行 1.正常执行scp命令 2.输入ctrl + z 暂停任务 3.bg将其放入后台 4.disown -h 将这个作业忽略HUP信号 5.测试会话中断,任务继 ...
- 初探Vue
Vue.js(读音/vju:/,类似于view),是近来比较火的前端框架,但一直没有怎么具体了解.实现过,就知道个啥的MVVM啦,数据驱动啦,等这些关于Vue的虚概念. 由于最近,小生在公司中,负责开 ...
- [笔记]HAproxy reload config file with uninterrupt session
HAProxy is a high performance load balancer. It is very light-weight, and free, making it a great op ...
- java中易错点(一)
由于replaceAll方法的第一个参数是一个正则表达式,而"."在正则表达式中表示任何字符,所以会把前面字符串的所有字符都替换成"/".如果想替换的只是&qu ...
- 为什么很多SaaS企业级产品都熬不过第一年
因工作缘由,笔者与周边数位SaaS企业级应用的创始人.运营负责人有过深入接触,发现一个有趣的现象:刚起步时,蓝图远志.规划清晰,但是一路下来,却异常艰难,有些甚至熬不过第一年,就关门歇业. 2015年 ...
- class-dump 反编译私有的库和应用
一.下载并安装class-dump 下载class-dump-3.5.dmg 点击下载 下载完成以后双击.dmg的文件,将里面的class-dump拷贝到/usr/local/bin 设置权限chm ...