python怎么提取列表的一列_如何在python中访问列表列表中的列

1586010002-jmsa.png

I have a 2D array in python modeled by a list of lists and I want to extract the column. I made a quick research and I found a way that uses numpy arrays. The problem is that I do not want to use numpy so I don't want to convert my list of lists into a numpy array and then use [:,1] syntax. I tried using it on a normal list of lists but it shows an error so it's not possible. I am asking for a similar thing for list of lists without having to go through each element(In numpy arrays, it's faster to access a column by using [:,1] syntax than iterating over the elements of the array).

I found this link but again it suggests iterating over elements without a shortcut.

Thanks in advance.

解决方案

List comprehensions are your friend when working with lists of lists:

In [111]: alist

Out[111]:

[[0, 1, 2, 3, 4, 5]

你可能感兴趣的:(python怎么提取列表的一列)