unzip array of arrays?

Rhodri James rhodri at wildebst.demon.co.uk
Thu Jan 22 19:17:18 EST 2009


On Thu, 22 Jan 2009 22:04:15 -0000, Tobiah <toby at tobiah.org> wrote:

> Although it's trivial to program, I wondered whether
> there was a builtin or particularly concise way to
> express this idea:
>
>> a = [(1, 2), (3, 4), (5, 6)]
>> field[a, 2]
> [2, 4, 6]
>
> where field() is some made up function.

If field() already exists, there's always a list
comprehension: [field(l) for l in a]

If you want that specific list:

>>> [l[1] for l in a]
[2, 4, 6]

-- 
Rhodri James *-* Wildebeeste Herder to the Masses



More information about the Python-list mailing list