idiom for list looping

Xavier Ho contact at xavierho.com
Wed Jul 29 13:16:41 CEST 2009


Ack, sent to the wrong email again.

On Wed, Jul 29, 2009 at 9:02 PM, superpollo <user at example.net> wrote:

>
> >>> print '\n'.join("%s - %s" % p for p in enumerate(nomi))
>  File "<stdin>", line 1
>    print '\n'.join("%s - %s" % p for p in enumerate(nomi))
>                                    ^
> SyntaxError: invalid syntax


lol, I knew I shouldn't have trusted untested code!


> >>> print '\n'.join(["%s - %s" % p for p in enumerate(nomi)])
> 0 - one
> 1 - two
> 2 - three
>

Yup.. but using a variable for the tuple itself was a good move though =P.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090729/d828df45/attachment.html>


More information about the Python-list mailing list