elegant python style for loops
Ant
antroy at gmail.com
Thu May 10 04:19:11 EDT 2007
On May 10, 6:51 am, ian.team.pyt... at saltmob.com wrote:
...
> into a list of tuples to allow moving through multiple lists, or is
> the for i in range(len(listkeys)): the only solution?
>
> Any suggestions?
For the specific case of indexing lists, the following is cleaner than
the 'for i in range...' solution above, and works in cases where
zipping the lists may not be appropriate:
for i, item in enumerate(mylist):
print "%s) My item: %s; My other item: %s" % (i, item,
my_non_iterable_object.thing_at(i))
--
Ant.
More information about the Python-list
mailing list