transforming a list into a string

Bengt Richter bokr at
Sun Aug 1 14:19:19 EDT 2004

On Sun, 1 Aug 2004 11:00:32 +1000, Andrew Bennetts <andrew-pythonlist at> wrote:
>It's a two-liner, not a one-liner (although it could be made into a
>one-liner with enough contortions...).
Another contortion ;-)

 >>> items = ['1','2','7','8','12','13']
assumed defined as before, then one line:

 >>> ''.join([i%2 and c+'},' or '{'+c+',' for i,c in enumerate(items)])[:-1]

Bengt Richter

More information about the Python-list mailing list