1-liner to iterate over infinite sequence of integers?

Will McGugan news at NOwillmcguganSPAM.com
Thu Oct 13 13:45:46 EDT 2005


Neal Becker wrote:
> I can do this with a generator:
> 
>     def integers():
>         x = 1
>         while (True):
>             yield x
>             x += 1
> 
> for i in integers(): 
> 
> Is there a more elegant/concise way?
> 

import itertools
for i in itertools.count():
	print i


Will McGugan
-- 
http://www.willmcgugan.com
"".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in 
"jvyy*jvyyzpthtna^pbz")



More information about the Python-list mailing list