18. Lambda Expressions Python 3


#1

Hi, here another difference I found in Python 3

garbled = "IXXX aXXmX aXXXnXoXXXXXtXhXeXXXXrX sXXXXeXcXXXrXeXt mXXeXsXXXsXaXXXXXXgXeX!XX"
message = str(filter(lambda x: x != "X", garbled))
print (message)

it print out

filter object at 0x00000000028FE5F8

instead of

I am another secret message!


#2

the way filter, map and reduce work is changed. We can fix it, we can do this:

garbled = "IXXX aXXmX aXXXnXoXXXXXtXhXeXXXXrX sXXXXeXcXXXrXeXt mXXeXsXXXsXaXXXXXXgXeX!XX"
message = "".join(list(filter(lambda x: x != "X", garbled)))
print (message)

its not really nice, but it works, see this stackoverflow question


#3

Yes it works, thanks


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.