If the values within each list are less than or equal to 2 remove them.
What I have tried:
check = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
output = list(filter(lambda x: x[0] <= 2, check))
return (output)
- expected output
[[3], [4, 5, 6], [7, 8, 9]]
If the values within each list are less than or equal to 2 remove them.
What I have tried:
check = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
output = list(filter(lambda x: x[0] <= 2, check))
return (output)
[[3], [4, 5, 6], [7, 8, 9]]
This is a way without using lambda:
output = [[y for y in x if y>2] for x in check]
What you want is a map to iterate to every list than you apply the filter function.
check = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
output = list(map(lambda x: list(filter(lambda y: y > 2,x)), check))
print(output)
[[3], [4, 5, 6], [7, 8, 9]]