When using the max() function in Python to find the maximum value in a list (or tuple, dict etc.) and there is a tie for maximum value, which one does Python pi
For Python 3, the behavior of max() in the case of ties is no longer just an implementation detail as detailed in the other answers. The feature is now guaranteed, as the Python 3 docs explicitly state:
If multiple items are maximal, the function returns the first one encountered. This is consistent with other sort-stability preserving tools such as
sorted(iterable, key=keyfunc, reverse=True)[0]andheapq.nlargest(1, iterable, key=keyfunc).