Sorting in Python is one line: sorted(values) gives a new, sorted list; values.sort() sorts the list in place and returns nothing. The real power is in the key parameter: from each element you produce the value it is to be sorted by.
people = [("Ece", 31), ("Can", 25), ("Ada", 31)]sorted(people, key=lambda p: p[1])# [("Can", 25), ("Ece", 31), ("Ada", 31)]sorted(people, key=lambda p: (-p[1], p[0]))# [("Ada", 31), ("Ece", 31), ("Can", 25)]
When the values come in only a few kinds (0, 1 and 2, say) there is no need to sort by comparing: count how many of each there are, then write that many out in order. That is one pass, faster than the general n log n sort.