sum(map(len, ["a", "aa", "aaa"])) gives me a map instead of a number.
I expected this to give the same result as sum(len(thing) for thing in ["a", "aa", "aaa"]) (that is 6).
I see that list(sum(map(len, ["a", "aa", "aaa"]))) returns me [1, 2, 3], as if the sum had no effect.
I assume there is a reason for such a behaviour. Is there an intended use case for this?
It appears that I was working in ipython and that the builtin sum function was masked by "function sum in module numpy.core.fromnumeric" (according to help(sum)). I suspect an effect of having issued the command %pylab.
__builtin__.sum(map(len, ["a", "aa", "aaa"])) gives the expected 6.
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