I've got a list of lists A
:
A = [ [0, 42, 2.6],
[1, 20, 5.6],
[2, 67, 3.5],
[3, 12, 3.2],
[4, 34, 1.1],
[5, 74, 4.7],
[6, 29, 2.9] ]
from which I'd like to extract a sub-list B
containing only those lists whose second columns are lower than 30 (i.e., B = [[1, 20, 5.6],[3, 12, 3.2],[6, 29, 2.9]]
)
Of course I may convert it to a numpy
and use a np.where
. However I was wondering whether there is a way of doing that just by using lists. I tried with a list comprehension, but I'm not very expert on that:
B = [x for x in len(A) if x[1] <= 30]
but it doesn't work, indeed. Any suggestion? Thanks in advance.