Extracting elements over multiple lists?

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Nov 7 13:51:31 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.
>
>
>
> Cheers
>   
This is a one liner, but since you asked something *pythonic*, John's 
solution is the best imo:

for arr in [a,b,c]:
  arr.pop(0)

(Peter's "del" solution is quite close, but I find the 'del' statement 
tricky in python and will mislead many python newcomers)

JM



More information about the Python-list mailing list