idiom for list looping

Xavier Ho contact at xavierho.com
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: <http://mail.python.org/pipermail/python-list/attachments/20090729/aa3e26bb/attachment-0001.html>


More information about the Python-list mailing list