Extracting elements over multiple lists?

Laurent Claessens moky.math at gmail.com
Tue Nov 8 02:07:39 EST 2011


Le 07/11/2011 19:01, JoeM a écrit :
> Thanks guys, I was just looking for a one line solution instead of a
> for loop if possible. Why do you consider
>
> [x.remove(x[0]) for x in [a,b,c]]
>
> cheating? It seems compact and elegant enough for me.

I have the feeling that it does not do what I expect it does just by 
seeing the line. It is list comprehension, but the point is absolutely 
not in creating a list.

I'd say it breaks the rule «Explicit is better than implicit.» while 
«Special cases aren't special enough to break the rules.»

But well... could be a matter of taste; I prefer the loop.

Laurent



More information about the Python-list mailing list