python 关于yield, generator, iterable
2015-12-07 11:39
561 查看
遍历一个list,寻找满足条件的元素。
如果这个list很长,则不要直接iterable 这个list,即使用for 遍历,将整个list全部放到memory中。最好的办法是用yield create一个generator。这样就是每scan一个元素就放入内存。
see http://pythontips.com/2013/09/29/the-python-yield-keyword-explained/
如果这个list很长,则不要直接iterable 这个list,即使用for 遍历,将整个list全部放到memory中。最好的办法是用yield create一个generator。这样就是每scan一个元素就放入内存。
see http://pythontips.com/2013/09/29/the-python-yield-keyword-explained/
相关文章推荐
- Python操作MySQL以及中文乱码的问题
- selenium webdriver python 操作IE浏览器
- Python语言assert用法
- Python的数据类型 字符串和编码
- selenium webdriver python 操作Chrome浏览器
- numpy数组 ndarray对象基本知识
- python之Lambda函数---笔记
- python --闭包
- 两个实用的Python的装饰器
- python pandas 自动填充,重新采样 resample
- Python关键字yield的解释
- python --对象的属性
- Python发送邮件
- python 利用time模块获取当前 日期时间
- python --上下文管理器
- python
- Python进阶09 动态类型
- Python进阶08 异常处理
- Python进阶07 函数对象
- Python进阶06 循环对象与迭代