Python syntax for a map(max()) call

Viewed 714

I came across this particular piece of code in one of "beginner" tutorials for Python. It doesn't make logical sense, if someone can explain it to me I'd appreciate it.

print(list(map(max, [4,3,7], [1,9,2])))

I thought it would print [4,9] (by running max() on each of the provided lists and then printing max value in each list). Instead it prints [4,9,7]. Why three numbers?

4 Answers

Most have answered OPs question as to why, Here's how to get that output using max:

a = [4,3,7]
b = [1,9,2]

print(list(map(max, [a, b])))

gives

[7, 9]
Related