enumerated while loop

Roald de Vries rdv at roalddevries.nl
Sat Jan 23 15:44:07 CET 2010

Dear all,

I sometimes want to use an infinite while loop with access to the loop  
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?

Kind regards, Roald

More information about the Python-list mailing list