unzip array of arrays?
Chris Rebert
clp2 at rebertia.com
Thu Jan 22 17:13:34 EST 2009
On Thu, Jan 22, 2009 at 2:04 PM, 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.
Python 2.6 (r26:66714, Nov 18 2008, 21:48:52)
[GCC 4.0.1 (Apple Inc. build 5484)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a= [(1, 2), (3, 4), (5, 6)]
>>> zip(*a)
[(1, 3, 5), (2, 4, 6)]
>>> zip(*a)[1]
(2, 4, 6)
Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
More information about the Python-list
mailing list