Get number of iteration

Jeff Epler jepler at unpythonic.net
Thu Jan 29 17:26:48 CET 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