0

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]]
    
DevScheffer
  • 491
  • 4
  • 15
Ross Smith
  • 11
  • 2

2 Answers2

3

This is a way without using lambda:

output = [[y for y in x if y>2] for x in check]
GabrielP
  • 777
  • 4
  • 8
2

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)
  • output
[[3], [4, 5, 6], [7, 8, 9]]
DevScheffer
  • 491
  • 4
  • 15