Select column from a list
somebody at somewhere.com
Fri Aug 28 20:57:28 CEST 2009
> 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.
> For example I have list called 'values'.
> When I write 'values' or 'values[:]' I'll get the first row.
> But when I write 'values[:]' I won't get the first column, but the
> first row again! I can't see why.
rows = [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
cols = zip(*rows)
To just get the second column:
More information about the Python-list