[Tutor] Composing lists from both items and other lists

Corey Richardson kb1pkl at aim.com
Wed Feb 2 00:39:47 CET 2011


On 02/01/2011 06:23 PM, Andre Engels wrote:
> 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?
> 

That's what I was looking for. The simplest things sometimes go right
over my head... Ignore my other post, but list comprehensions are a
useful thing to know.



More information about the Tutor mailing list