Generator using item[n-1] + item[n] memory

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Feb 15 12:03:27 CET 2014


On Fri, 14 Feb 2014 22:21:11 -0500, Roy Smith used a generator:

> print g1.next()

Roy, unless you're stuck with Python 2.5 (or older!), you ought to use 
the built-in function next(g1) rather than directly call the next method. 
Not only is this the recommended way to do it, but it's also more future-
proof (Python 3 drops the next method and makes it a dunder method) and 
has more functionality (the next() function takes an optional default 
value).


-- 
Steven



More information about the Python-list mailing list