do you master list comprehensions?

Max M maxm at mxm.dk
Mon Dec 13 16:07:19 EST 2004


Will Stuyvesant 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.

In that case you might be more comfortable with:

data = [['foo','bar','baz'],['my','your'],['holy','grail']]
result = []
for l in data:
     result += l


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science



More information about the Python-list mailing list