I have two lists:
a,b=[1,2],[33,44]
I want to explore both their minimum. But
>>> min(a,b)
returns [1, 2] as min()
With more than one argument, return the smallest of the arguments.
Same happens if I use map() as
map(min,a,b)
is mostly equivalent to:
[f(x1, x2) for x1, x2 in zip(sequence1, sequence2)]
as already stated in this answer.
>>> map(min,[a,b])
[1, 33]
gives me what I want but I don’t really understand why. Can someone explain?
The answer is in Python
mapdocumentation:When you call:
You are actually passing two iterables to
map. This successively callsmin(1, 33)andmin(2, 44), thus returning[1, 2].However, in:
There is a single iterable, and
mapcallsminon each element of the sequence:min([1, 2])which yields1min([33, 44])which yields33The result, as expected, is
[1, 33].