Matrix (list-in-list), how to get a column?

Batista, Facundo FBatista at uniFON.com.ar
Thu Oct 21 11:25:30 EDT 2004


[Arvid Andersson]

#- Is there a more elegant solution than this?
#- 
#- col1 = []
#- col2 = []
#- for i in range(len(data)):
#-   col1 += [a[i][0]]
#-   col2 += [a[i][1]]

>>> data = [[1, 2], [3, 4], [5, 6]]
>>> [x[0] for x in data]
[1, 3, 5]
>>> [x[1] for x in data]
[2, 4, 6]
>>> 

.	Facundo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20041021/55753a74/attachment.html>


More information about the Python-list mailing list