[Tutor] Composing lists from both items and other lists

Andre Engels andreengels at gmail.com
Wed Feb 2 00:23:12 CET 2011


On Tue, Feb 1, 2011 at 9:40 PM, John Simon <bigjohnexpress at gmail.com> wrote:
> 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?

Is:

[start] + items + [end]

lightweight enough?


-- 
André Engels, andreengels at gmail.com


More information about the Tutor mailing list