for loop: range() result has too many items
mnordhoff at mattnordhoff.com
Wed Oct 14 05:20:58 CEST 2009
Andre Engels wrote:
> However, I think that the better Python way would be to use a generator:
> def infinite_numbergenerator():
> n = 0
> while True:
> yield n
> n += 1
> for i in infinite_numbergenerator():
That's what itertools.count() is for.
It'll be faster, too, since it's written in C. Not that it really
matters, but it's always nice.
More information about the Python-list