idiom for list looping

Xavier Ho contact at xavierho.com
Wed Jul 29 07:00:37 EDT 2009


On Wed, Jul 29, 2009 at 8:52 PM, MRAB <python at mrabarnett.plus.com> wrote:

> Slightly shorter:
>
> print '\n'.join("%s - %s" % p for p in enumerate(nomi))
>
> :-)
>
That's cool. Does that make the "list" a tuple? (not that it matters, I'm
just curious!)

I just tested for a list of 1000 elements (number in letters from 1 to 1000
code I wrote for doing project euler problem 17), and the join method is 0.1
seconds faster than the for loop! Woo!? ;p
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090729/41513f45/attachment.html>


More information about the Python-list mailing list