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
Your question somewhat leads to a note. When sorting a data structure, there is often a desire to keep relative order of objects that are considered equal for the purposes of comparison. This would be known as a stable sort.
If you absolutely needed this feature, you could do a sort()
, which will be stable and then have knowledge of the order relative to the original list.
As per python itself, I don't believe that you get any guarantee of which element you will get when you call max()
. Other answers are giving the cpython answer, but other implementations (IronPython, Jython) could function differently.