4 ms·
No, what Python suggests is just returning the value you sort on, or a tuple of the values to sort on. cmp() is deprecated because there is seldom reason to us
by sametmax 7y ago
No, what Python suggests is just returning the value you sort on, or a tuple of the values to sort on.
cmp() is deprecated because there is seldom reason to use it anymore.
E.G:
Sorting words according to their number of letter is just:
sorted(words, key=len)
You don't return 1, -1 or 0.
If you want to rank participants of a game in a dictionary of scores using names as keys and points as values, you would to:
sorted(scores.items(), key=lambda score: score[1])
Again you don't return 1, -1 or 0, just the value that is significant. It makes it very, very simple to reason about.