I tried 2 snippets to figure out the difference between python lambda and regular function.
this one get what is expected.
b = range(6)
def greater_than2(b):
if b > 2:
return b
print(list(filter(lambda x: x > 2, b)))
print(list(filter(greater_than2, b)))
both print give [3, 4, 5].
but something goes with this one
b = range(6)
def less_than2(b):
if b < 2:
return b
print(list(filter(lambda x: x < 2, b)))
print(list(filter(less_than2, b)))
i got following output
[0, 1]
[1]
so, what the difference between the lambda and less_than2 function?
b. Whenbis zero,less_than2(b)returns0, which is a falsey value.