python 关于yield, generator, iterable

遍历一个list,寻找满足条件的元素。

如果这个list很长,则不要直接iterable 这个list,即使用for 遍历,将整个list全部放到memory中。最好的办法是用yield create一个generator。这样就是每scan一个元素就放入内存。


see  http://pythontips.com/2013/09/29/the-python-yield-keyword-explained/

你可能感兴趣的:(python 关于yield, generator, iterable)