<p>因为它返回一个迭代器,所以省略了在内存中存储完整大小的列表。这样你就可以很容易地在将来重复它,而不会对记忆造成任何痛苦。可能你甚至不需要一个完整的清单,但它的一部分,直到你的条件达到。</p>
<p>你可以发现这个<a href="https://docs.python.org/3/glossary.html#term-iterator" rel="noreferrer">docs</a>很有用,迭代器非常棒。</p>
<blockquote>
<p>An object representing a stream of data. Repeated calls to the iterator’s <code>__next__()</code> method (or passing it to the built-in function <code>next()</code>) return successive items in the stream. When no more data are available a <code>StopIteration</code> exception is raised instead. At this point, the iterator object is exhausted and any further calls to its <code>__next__()</code> method just raise <code>StopIteration</code> again. Iterators are required to have an <code>__iter__()</code> method that returns the iterator object itself so every iterator is also iterable and may be used in most places where other iterables are accepted. One notable exception is code which attempts multiple iteration passes. A container object (such as a <code>list</code>) produces a fresh new iterator each time you pass it to the <code>iter()</code> function or use it in a for loop. Attempting this with an iterator will just return the same exhausted iterator object used in the previous iteration pass, making it appear like an empty container. </p>
</blockquote>