idiom for list looping

Xavier Ho contact at
Wed Jul 29 06:37:44 EDT 2009

> superpollo wrote:
>> for (i, e) in enumerate(nomi):
>>    print i, "-", e
>> Just to be random:

print '\n'.join(["%s - %s" % (i, e) for i, e in enumerate(nomi)])

This has one advantage: only print once. So it's slightly faster if you have
a list of a large amount.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list