Submit Search
Upload
Python generators
•
0 likes
•
597 views
Yao Zuo
Follow
讲述Python生成器的知识
Read less
Read more
Technology
Report
Share
Report
Share
1 of 17
Download now
Download to read offline
Recommended
JavaScript现代化排错实践
JavaScript现代化排错实践
jeffz
IEEE 2015
Automatic face naming by learning discriminative affinity matrices from weakl...
Automatic face naming by learning discriminative affinity matrices from weakl...
Raja Ram
Python 入门第一课。包括准备工作、安装方法、常用的资源等
Python First Class
Python First Class
Yao Zuo
Integrating mobile access with university data processing in the cloud
Integrating mobile access with university data processing in the cloud
Integrating mobile access with university data processing in the cloud
Raja Ram
讲述Python中和HTTP相关的知识,以ChinaUnicom模拟登陆和抓取人人日志举例,主要用到Requests这个库
Python HTTP
Python HTTP
Yao Zuo
IEEE PAPER
A method for detecting abnormal program behavior on embedded devices
A method for detecting abnormal program behavior on embedded devices
Raja Ram
This document presents some commonly followed business processes across most organizations. The process designs have been created using IntelliPro BPMS.
IntelliPro BPMS - Process Frameworks
IntelliPro BPMS - Process Frameworks
iLeap
This document explains how once can build and automate a business process using IntelliPro BPMS. It has step-by-step explanation and illustration of process automation.
How to build and automate your first process in IntelliPro BPMS?
How to build and automate your first process in IntelliPro BPMS?
iLeap
Recommended
JavaScript现代化排错实践
JavaScript现代化排错实践
jeffz
IEEE 2015
Automatic face naming by learning discriminative affinity matrices from weakl...
Automatic face naming by learning discriminative affinity matrices from weakl...
Raja Ram
Python 入门第一课。包括准备工作、安装方法、常用的资源等
Python First Class
Python First Class
Yao Zuo
Integrating mobile access with university data processing in the cloud
Integrating mobile access with university data processing in the cloud
Integrating mobile access with university data processing in the cloud
Raja Ram
讲述Python中和HTTP相关的知识,以ChinaUnicom模拟登陆和抓取人人日志举例,主要用到Requests这个库
Python HTTP
Python HTTP
Yao Zuo
IEEE PAPER
A method for detecting abnormal program behavior on embedded devices
A method for detecting abnormal program behavior on embedded devices
Raja Ram
This document presents some commonly followed business processes across most organizations. The process designs have been created using IntelliPro BPMS.
IntelliPro BPMS - Process Frameworks
IntelliPro BPMS - Process Frameworks
iLeap
This document explains how once can build and automate a business process using IntelliPro BPMS. It has step-by-step explanation and illustration of process automation.
How to build and automate your first process in IntelliPro BPMS?
How to build and automate your first process in IntelliPro BPMS?
iLeap
Marketing Portfolio
Marketing Portfolio
Gary Little
BASE PAPER MATLAB
06542014
06542014
Raja Ram
Multi transmit beam forming for fast cardiac ppt
Multi transmit beam forming for fast cardiac
Multi transmit beam forming for fast cardiac
Raja Ram
Base Paper
831 panda public-auditing-for-shared-data-with-efficient-user-revocation-in-t...
831 panda public-auditing-for-shared-data-with-efficient-user-revocation-in-t...
Raja Ram
Design Portfolio - Link Version
Design Portfolio - Link Version
Nathan Jones
This document has a comprehensive overview of reference customer projects. It offers a high-level overview of BPM implementations using IntelliPro BPMS across several verticals such as manufacturing, government, healthcare and processes spanning different functions such as HR, Administration and more.
IntelliPro BPMS - Reference Customer Implementation Guide
IntelliPro BPMS - Reference Customer Implementation Guide
iLeap
IEEE 2015
Heterogeneous heed protocol for wireless sensor networks springer
Heterogeneous heed protocol for wireless sensor networks springer
Raja Ram
IEEE 2015
Face recognition across non uniform motion blur, illumination, and pose
Face recognition across non uniform motion blur, illumination, and pose
Raja Ram
Novel modilo based aloha anti collision in RFID
Novel modilo based aloha anti collision
Novel modilo based aloha anti collision
Raja Ram
การแยกตัวประกอบของพหุนาม
การแยกตัวประกอบของพหุนาม
Piyanouch Suwong
Cva slides
Cva slides
Kiel Deveras
More Related Content
Viewers also liked
Marketing Portfolio
Marketing Portfolio
Gary Little
BASE PAPER MATLAB
06542014
06542014
Raja Ram
Multi transmit beam forming for fast cardiac ppt
Multi transmit beam forming for fast cardiac
Multi transmit beam forming for fast cardiac
Raja Ram
Base Paper
831 panda public-auditing-for-shared-data-with-efficient-user-revocation-in-t...
831 panda public-auditing-for-shared-data-with-efficient-user-revocation-in-t...
Raja Ram
Design Portfolio - Link Version
Design Portfolio - Link Version
Nathan Jones
This document has a comprehensive overview of reference customer projects. It offers a high-level overview of BPM implementations using IntelliPro BPMS across several verticals such as manufacturing, government, healthcare and processes spanning different functions such as HR, Administration and more.
IntelliPro BPMS - Reference Customer Implementation Guide
IntelliPro BPMS - Reference Customer Implementation Guide
iLeap
IEEE 2015
Heterogeneous heed protocol for wireless sensor networks springer
Heterogeneous heed protocol for wireless sensor networks springer
Raja Ram
IEEE 2015
Face recognition across non uniform motion blur, illumination, and pose
Face recognition across non uniform motion blur, illumination, and pose
Raja Ram
Novel modilo based aloha anti collision in RFID
Novel modilo based aloha anti collision
Novel modilo based aloha anti collision
Raja Ram
การแยกตัวประกอบของพหุนาม
การแยกตัวประกอบของพหุนาม
Piyanouch Suwong
Cva slides
Cva slides
Kiel Deveras
Viewers also liked
(11)
Marketing Portfolio
Marketing Portfolio
06542014
06542014
Multi transmit beam forming for fast cardiac
Multi transmit beam forming for fast cardiac
831 panda public-auditing-for-shared-data-with-efficient-user-revocation-in-t...
831 panda public-auditing-for-shared-data-with-efficient-user-revocation-in-t...
Design Portfolio - Link Version
Design Portfolio - Link Version
IntelliPro BPMS - Reference Customer Implementation Guide
IntelliPro BPMS - Reference Customer Implementation Guide
Heterogeneous heed protocol for wireless sensor networks springer
Heterogeneous heed protocol for wireless sensor networks springer
Face recognition across non uniform motion blur, illumination, and pose
Face recognition across non uniform motion blur, illumination, and pose
Novel modilo based aloha anti collision
Novel modilo based aloha anti collision
การแยกตัวประกอบของพหุนาม
การแยกตัวประกอบของพหุนาม
Cva slides
Cva slides
Python generators
1.
Python Generators by laike9m laike9m@gmail.com https://github.com/laike9m
2.
You don’t know
what you don’t know 听说过,但不理解 >> 没听说过
3.
4.
5.
6.
>>> def gen_ab(): ... print('starting...') ... yield
'A' ... print('here comes B:') ... yield 'B' ... print('the end.') g = gen_ab(), 停在这里 第一次调用next(), 停在这里 第二次调用next(), 停在这里 生成器函数可以看成一串事件,yield暂停执行,next恢复执行 “yield 是 具有 暂停功能 的 return”
7.
斐波那契数列: 0,1,1,2,3,5,8,11,19,... 前两个数是0,1,后一个数是前两个数之和 斐波那契数列生成器
8.
for 循环 每次都会调用next() 更深入的讨论:interator(迭代器) 每次都把返回的a输出 注意yield是“具有暂停功能的return” return a
( = yield a ) fib_number = a 然后打印出来
9.
• 循环就是一个事件流,只不过里面 包含了一些条件判断 def fib(max): a,
b = 0, 1 while a < max: yield a a, b = b, a+b 等价于 def fib(max): a, b = 0, 1 if a < max: yield a a, b = b, a+b if a < max: yield a a, b = b, a+b if a < max: yield a a, b = b, a+b ...
10.
• 一起写一个斐波那契生成器 • enumerate
函数
11.
list() : 调用next()直到不能调用为止,并且把返回值存入列表,实质就是列表解析 [i
for i in enumerate(seasons)]
12.
13.
g.next()是Python2.X 的写法,对应 Python3.X中的next(g)
14.
• 有yield的函数:生成器函数 • yied是带暂停功能的return •
for, list 本质上是在调用next(obj) • 把生成器函数看成事件流,yield暂停,next继续执行 • 生成器函数内部通常包含循环,循环也是事件流 • 把列表解析的中括号换成小括号就是生成器表达式
15.
•快 • 内存占用小 需要的时候才会产生 • 语义上的含义 一次性使用 •
保存函数的当前执行环境,包括所有局部变量等
16.
http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained
17.
Q&A
Download now