indexed() generator

Magnus Lie Hetland mlh at vier.idi.ntnu.no
Wed Jan 23 10:05:11 EST 2002


In article <mailman.1011750813.24541.python-list at python.org>, 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
http://hetland.org                                  http://anygui.org



More information about the Python-list mailing list