If you just want to call the lambda function, you just use it as a function:
print (lambda x: x=="2341")(dict["Alice"])
This gives the expected result (true).
When you use filter , it treats its second argument as a list, so "2341" is treated as a list of characters ['2', '3', '4', '1'] , none of which are equal to β2341β.
An interesting thing that I just found out: Python 3 returns filter objects from the filter() function, so the proper use of a filter becomes
print( list( filter( lambda x: x, dict['Alice'] ) ) )
And this returns ['2', '3', '4', '1'] , which would have avoided the initial confusion.
source share