Get number of iteration

Jeff Epler jepler at unpythonic.net
Thu Jan 29 11:26:48 EST 2004


You're looking for the "enumerate" builtin function in 2.3.

    for i, x in enumerate(l):
        print x
        print i
        print "next"

You can define a "poor man's" enumerate in 2.2:

    def enumerate(seq):
        return zip(range(len(seq)), l)

but the enumerate in 2.3 is an iterator, not a sequence.

Jeff




More information about the Python-list mailing list