enumerated while loop
Roald de Vries
rdv at roalddevries.nl
Sat Jan 23 16:06:16 CET 2010
On Jan 23, 2010, at 3:50 PM, Grant Edwards wrote:
> On 2010-01-23, Roald de Vries <rdv at roalddevries.nl> wrote:
>> Dear all,
>> I sometimes want to use an infinite while loop with access to the
>> index, like this:
>> def naturals():
>> i = 0
>> while True:
>> yield i
>> y += 1
>> for i in naturals():
>> I assume a function like 'naturals' already exists, or a similar
>> construction for the same purpose. But what is it called?
> xrange(), except that you need to provde an upper limit.
I'm sorry, Grant, but you exactly miss my point ;-). The essence of
this is that it's endless.
More information about the Python-list