it allows to define a criterion which replaces the <
comparison between elements.
For instance:
>>>l = ["hhfhfhh","xx","123455676883"]
>>>max(l, key=len)
'123455676883'
returns the longest string in the list which is "123455676883"
Without it, it would return "xx"
because it’s the highest ranking string according to string comparison.
>>>l = ["hhfhfhh","xx","123455676883"]
>>>max(l)
'xx'
2
solved What does this `key=func` part mean in `max(a,b,c,key=func)` in Python?