Select column from a list

Vlastimil Brom vlastimil.brom at gmail.com
Fri Aug 28 05:28:38 EDT 2009


2009/8/28 hoffik <beorn at seznam.cz>:
>
> Hello,
>
> I'm quite new in Python and I have one question. I have a 2D matrix of
> values stored in list (3 columns, many rows). I wonder if I can select one
> column without having to go through the list with 'for' command.
> ...

I guess, it won't be possible without an explicit or implicit loop;
you may try:

>>> from operator import itemgetter
>>> nested_list = [[1, 2, 3], [10, 20, 30], [100, 200, 300]]
>>> map(itemgetter(1), nested_list)
[2, 20, 200]
>>>

vbr



More information about the Python-list mailing list