1-liner to iterate over infinite sequence of integers?
Will McGugan
news at NOwillmcguganSPAM.com
Thu Oct 13 14:00:44 EDT 2005
Will McGugan wrote:
> 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
>
Actualy itertools.count(1) to start at 1..
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