Content deleted Content added
generators in general (requires copyediting) |
m copy-friendly code |
||
Line 11:
An example Python generator:
<pre>
if n == 0:
yield [] </pre>
In Python, a generator can be thought of as an iterator that contains a frozen function call. Whenever the iterator's <code>next()</code> method is called, the frozen function call resumes where it was left off and runs until it reaches a <code>yield</code> statement. Then the function call is frozen again, the iterator spits out the yielded value, and execution continues with the iterator's caller.
|