I have a 2d List in python like below:
[[0,2,3,4],[0,1,3,4],[1,2,3,4]]
And I want to get only items that the first item is zero. In this Example the first and second item. How could I do this?
I have a 2d List in python like below:
[[0,2,3,4],[0,1,3,4],[1,2,3,4]]
And I want to get only items that the first item is zero. In this Example the first and second item. How could I do this?
In [46]: a = [[0,2,3,4],[0,1,3,4],[1,2,3,4]]
In [47]: [i for i in a if i[0] == 0]
Out[47]: [[0, 2, 3, 4], [0, 1, 3, 4]]
OR
In [49]: list(filter(lambda x: x[0] == 0, a))
Out[49]: [[0, 2, 3, 4], [0, 1, 3, 4]]