Website hosting and domain hosting service by

 Back to Index

7 PEP 279: enumerate()

A new built-in function, enumerate(), will make certain loops a bit clearer. enumerate(thing), where thing is either an iterator or a sequence, returns a iterator that will return (0, thing[0]), (1, thing[1]), (2, thing[2]), and so forth.

A common idiom to change every element of a list looks like this:


for i in range(len(L)):
    item = L[i]
    # ... compute some result based on item ...
    L[i] = result

This can be rewritten using enumerate() as:


for i, item in enumerate(L):
    # ... compute some result based on item ...
    L[i] = result




2002-2004 Website Hosting Service


Disclaimer: This documentation is provided only for the benefits of our hosting customers.
For authoritative source of the documentation, please refer to


Register domain name by Cheap Domain Registrar with free domain hosting services

Cheap domain name - Cheap domain name registration service including free domain hosting services offers domain name registration, domain name transfer and domain search services