max - Which maximum does Python pick in the case of a tie? -


when using max() function in python find maximum value in list (or tuple, dict etc.) , there tie maximum value, 1 python pick? random?

this relevant if, instance, 1 has list of tuples , 1 selects maximum (using key=) based on first element of tuple there different second elements. how python pick 1 pick maximum?

i'm working in python v2.6.

on python 2, isn't specified in documentation , isn't in portable in-python section of standard library, behaviour may vary between implementations.

in source cpython 2.7 implemented in ./python/bltinmodule.c builtin_max [source], wraps more general min_max function  [source].

min_max iterate through values , use pyobject_richcomparebool [docs] see if greater current value. if so, greater value replaces it. equal values skipped over.

the result first maximum chosen in case of tie.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -