Extracting elements over multiple lists?
Peter Otten
__peter__ at web.de
Mon Nov 7 13:33:01 EST 2011
JoeM wrote:
> 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 think it's a misconception that you are avoiding the for-loop. You move it
into [...] and declare it more elegant, but in reality you are creating a
throwaway list of None-s. You are adding cruft to your code.
That is not only superfluous, but also misleading. A simple for-loop like
for x in a, b, c:
del x[0]
on the other hand makes your intention crystal-clear.
More information about the Python-list
mailing list