Extracting elements over multiple lists?

Dave Angel d at davea.name
Mon Nov 7 15:06:25 EST 2011


On 11/07/2011 01:01 PM, 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
Are you considering the possibility that two of these names might 
reference the same list?

a = [42, 44, 6, 19, 48]
b = a
c = b


for x in [a,b,c]:
     x.remove(x[0])

now a will have  [19,48] as its content.



-- 

DaveA




More information about the Python-list mailing list