best way to do this

T

TP

Hi everybody,

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?

Thanks

Julien
--
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.9&1+,\'Z
(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)
 
H

Hrvoje Niksic

TP said:
Hi everybody,

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?

Quicker? Hard to say. Using itertools elegantly? Definitely:

list(chain(*c))

As an added benefit, it works regardless of the number of elements in
the tuple. (Also assumes from itertools import chain for effect.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top