[Tutor] Composing lists from both items and other lists

John Simon bigjohnexpress at gmail.com
Tue Feb 1 21:40:39 CET 2011


I'm looking for a way to flatten lists inside a list literal, kind of like
this:

>>> start = '('
>>> end = ')'
>>> items = ['abc', '+', 'def']
>>> [start, *items, end]
['(', 'abc', '+', 'def', ')']

Of course, the star doesn't work there. Is there any easy,
syntactically-lightweight way to get that output?

Thanks,
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110201/b91521c1/attachment.html>


More information about the Tutor mailing list