Iterating over multiple lists (a newbie question)

Greg Jorgensen gregj at pobox.com
Sun Jan 7 05:07:07 EST 2001


"Alex Martelli" <aleaxit at yahoo.com> wrote in message
news:937rgo01rvo at news1.newsguy.com...
> Almost, not quite.  It's closer to:
>     i = 0
>     while 1:
>         try:
>             item = list[i]
>         except IndexError:
>             break
>         i += 1
>         # the rest goes here
>
> I.e., the sequence being iterated upon with for does not have to
> define a 'length': rather, it lets the iteration know that it's done
> by raising an IndexError exception.

Thanks, Alex. That makes writing iterators even easier.

--
Greg Jorgensen
PDXperts
Portland, Oregon, USA
gregj at pobox.com





More information about the Python-list mailing list