best way to do this

thor yaksavage at gmail.com
Wed Dec 3 04:38:36 CET 2008


On Dec 2, 10:09 pm, TP <Tribulati... at Paralleles.invalid> wrote:
> Hi everybody,
>
> >>> c=[(5,3), (6,8)]
>
> From c, I want to obtain a list with 5,3,6, and 8, in any order.
> I do this:
>
> >>> [i for (i,j) in c] + [ j for (i,j) in c]
>
> [5, 6, 3, 8]
>
> Is there a quicker way to do this?
>

>>> c = [(5, 3), (6, 8)]
>>> [x for t in zip(*c) for x in t]
[5, 6, 3, 8]



More information about the Python-list mailing list