indexed() generator

Magnus Lie Hetland mlh at
Wed Jan 23 16:05:11 CET 2002

In article <mailman.1011750813.24541.python-list at>, Delaney,
Timothy wrote:

>A perhaps better method would be:
>def indexed (seq, start=0)
>    i = start
>    for obj in seq:
>        yield i, obj
>        i += 1
>(sometimes a non-zero start index is wanted).

Perhaps you should add a step while you're at it? And maybe even stop
(in case you don't want the entire sequence)? Just keeping some
similarity with range()...

>Tim Delaney


Magnus Lie Hetland                                  The Anygui Project                        

More information about the Python-list mailing list