Here I am appending items into a list in an iterative manner:
l = []
for i in range(4):
l.append(i)
print l # Ans: [0, 1, 2, 3]
Where as, if I use map() to do the same, I get a different result
l = []
map(l.append, range(4)) # Ans: [None, None, None, None]
Python map
returns the values returned for each function call in a list (or a generator).
In this case list.append
returns None
.
Also l
is mutable, so it should contain the items.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With