赋值

>>> 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读书杂记的更多相关文章

  1. Web Scraping with Python读书笔记及思考

    Web Scraping with Python读书笔记 标签(空格分隔): web scraping ,python 做数据抓取一定一定要明确:抓取\解析数据不是目的,目的是对数据的利用 一般的数据 ...

  2. 【Reading Note】算法读书杂记

    1 排序 排序基本信息 稳定性:排序前大的数在排序后,大的数依然保持不变就是稳定排序,反之不稳定 内外排序:根据待排序的记录是否放在内存里面区分的.诸如:插入排序(直接插入&希尔).交换排序( ...

  3. Python Geospatial Development reading note(1)

    chapter 1, Summary: In this chapter, we briefly introduced the Python programming language and the m ...

  4. Python学习杂记

    Python中关键字yield有什么作用? 首先得理解generators,而理解generators前还要理解iterables: 你可以用在for...in...语句中的都是可迭代的:比如list ...

  5. python初学杂记

    python常用命令: 1.python 或者 python3  打开交互式python解释器 2.python hello.py   通过命令提示符运行python脚本 交互式python解释器常用 ...

  6. Python 读书系列

    1. 原文<A byte of Python> 翻译版:<<简明Python教程>> 2. Python:核心编程

  7. OK - A byte of python - 读书笔记

    看这本书的目的:再熟悉基本概念. 大部分都是知道,但是需要 明确 出来的 概念. - 欢迎吐槽错误,非常感谢. <A byte of python> - THIS 1. 组织行 - 形式: ...

  8. 流畅的Python读书笔记(二)

    2.1 可变序列与不可变序列 可变序列 list. bytearray. array.array. collections.deque 和 memoryview. 不可变序列 tuple. str 和 ...

  9. Reading | 《Python基础教程》第1次阅读

    目录 一.基础知识 1.数和表达式 浮点除法和整数除法 负数整除和取余 圆整 乘方运算 2.变量名 3.获取用户输入 4.模块 5.让脚本像普通程序一样 6.字符串 单.双引号 引号的转义 字符串拼接 ...

随机推荐

  1. Ubuntu 14.04中Elasticsearch集群配置

    Ubuntu 14.04中Elasticsearch集群配置 前言:本文可用于elasticsearch集群搭建参考.细分为elasticsearch.yml配置和系统配置 达到的目的:各台机器配置成 ...

  2. Android注解使用之注解编译android-apt如何切换到annotationProcessor

    前言: 自从EventBus 3.x发布之后其通过注解预编译的方式解决了之前通过反射机制所引起的性能效率问题,其中注解预编译所采用的的就是android-apt的方式,不过最近Apt工具的作者宣布了不 ...

  3. 模拟AngularJS之依赖注入

    一.概述 AngularJS有一经典之处就是依赖注入,对于什么是依赖注入,熟悉spring的同学应该都非常了解了,但,对于前端而言,还是比较新颖的. 依赖注入,简而言之,就是解除硬编码,达到解偶的目的 ...

  4. mybatis plugins实现项目【全局】读写分离

    在之前的文章中讲述过数据库主从同步和通过注解来为部分方法切换数据源实现读写分离 注解实现读写分离: http://www.cnblogs.com/xiaochangwei/p/4961807.html ...

  5. 深入node之Transform

    Transform流特性 在开发中直接接触Transform流的情况不是很多,往往是使用相对成熟的模块或者封装的API来完成流的处理,最为特殊的莫过于through2模块和gulp流操作.那么,Tra ...

  6. [C#] C# 知识回顾 - 特性 Attribute

    C# 知识回顾 - 特性 Attribute [博主]反骨仔 [原文地址]http://www.cnblogs.com/liqingwen/p/5911289.html 目录 特性简介 使用特性 特性 ...

  7. BPM与 SAP & Oracle EBS集成解决方案分享

    一.需求分析 SAP和Oracle EBS都是作为全球顶级的的ERP产 品,得到了众多客户的青睐.然而由于系统庞大.价格昂贵以及定位不同,客户在实施过程中经常会面临以下困惑: 1.SAP如何实现&qu ...

  8. 跟着老男孩教育学Python开发【第三篇】:Python函数

    set 无序,不重复,可嵌套. 函数 创建函数: 1.def关键字,创建函数 2.函数名 3.() 4.函数体 5.返回值 发邮件函数 def sendmail():     import smtpl ...

  9. Spring MVC初始化参数绑定

    初始化参数绑定与类型转换很类似,初始化绑定时,主要是参数类型 ---单日期 在处理器类中配置绑定方法  使用@InitBinder注解 在这里首先注册一个用户编辑器 参数一为目标类型   proper ...

  10. Flume1 初识Flume和虚拟机搭建Flume环境

    前言:       工作中需要同步日志到hdfs,以前是找运维用rsync做同步,现在一般是用flume同步数据到hdfs.以前为了工作简单看个flume的一些东西,今天下午有时间自己利用虚拟机搭建了 ...