I am using Python3.6 and am trying to figure out ways in which we can use map
with multiple arguments.
When I run,
def multiply(x, y, z):
return x * y * z
products = map(multiply, [3,6], [1,8], [3,5])
list(products)
returns [9, 240]
as expected
However, when I specify a default value for z,
def multiply(x, y, z = [3,5]):
return x * y * z
products = map(multiply, [3,6], [1,8])
list(product)
returns
[[3, 5, 3, 5, 3, 5],
[3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5,
3,
5]]
Why does Python differ in the way it runs map
in the two scenarios?