+ 3
Why is the result of this code not a list, or is my code wrong?
a = [1,2,3] b = map(lambda x: x**2, a) print (b)
3 Respuestas
+ 4
The map function is in fact an object. So b isn't a list but an iterable map object... That can be converted into a list.
+ 3
Okay, so i converted the end result using the "convert to list" function and it worked. I wrote print(list(b)) instead of print(b). I'm not sure why it doesn't give a straight list result. :(
+ 3
just to add (if it helps) ....as the map returns an iterable object, you can do this:
a = [1, 2, 3]
for a in map(lambda x: x**2, a):
print(a)