do you master list comprehensions?
fredrik at pythonware.com
Mon Dec 13 22:48:53 CET 2004
Max M wrote:
>> I tried funnies like [[w for w in L] for L in data],
>> that is correct syntax, but you'd never guess.
> That is absolutely correct. It's not a funnie at all. If you find it odd it's only because you are
> not used to list comprehensiones.
well, syntactically correct or not, it doesn't do what he want...
> In that case you might be more comfortable with:
> data = [['foo','bar','baz'],['my','your'],['holy','grail']]
> result = 
> for l in data:
> result += l
how about (slightly evil):
result = ; map(result.extend, data)
More information about the Python-list