Generator/Exponential: Difference between revisions

(Proper use of iterators. It's wrong to use the __next__ function when there's next().)
Line 1,147:
In Python, any function that contains a yield statement becomes a generator. The standard libraries itertools module provides the following functions used in the solution: [http://docs.python.org/library/itertools.html#itertools.count count], that will count up from zero; and [http://docs.python.org/library/itertools.html#itertools.islice islice], which will take a slice from an iterator/generator.
 
{{works with|Python|2.6+ and 3.x}} (in versions prior to 2.6, replace <code>next(something)</code> with <code>something.next()</code>)
<lang python>from itertools import islice, count
 
Anonymous user