I'm new to python lambda functions. So this question maybe a dummy one. I have the following sample code in python:
halve_evens_only = lambda nums: map(lambda i: i/2, filter(lambda i: not i%2, nums))
by calling this function like halve_evens_only([2,5,7,89,36]) I got the following output:
<map object at 0x02937190>
Is that a generator? How can I get the value ( I mean a list ) as an output of this function?
list()on it will work.mapit's generally cleaner to use a list comprehension.<function <lambda> at 0x7f7de21f31f0>. How are you getting<map object at 0x02937190>filter, and a listcomp could combine both operations into one. What they wrote could simplify to (and make an actuallistin the process)[i / 2 for i in nums if not i % 2](ori // 2to avoid conversion tofloat, which seems like the right idea given the division will be lossless).