1

I've defined the function

def f(array):
    return list(filter(lambda x: (x is not 0.0) and (x is not 0), array))

and here's what happens we I try to pass a list with a 0.0 in it.

>>> f([0.0, 1, 0, 2, False])
[0.0, 1, 2, False]

What I'd expect returned is [1, 2, False] since my filter should have thrown out the 0.0 and 0, but not the False.

For some reason, the filter is not picking up the x is not 0.0 part, but it's working on the x is not 0 part fine. I'm dumbfounded.


Edit: I've added in a False value to show why I'm not just using x != 0.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Bobbie D
  • 183
  • 4

0 Answers0