In Python you can for example sort tuples sorted([(2,2),(1,2),(2,1),(1,1)]) and get [(1, 1), (1, 2), (2, 1), (2, 2)].
sorted([(2,2),(1,2),(2,1),(1,1)])
[(1, 1), (1, 2), (2, 1), (2, 2)]
You can also use custom k
You don't need a extra function. You can also do it:
medals_map = {'Gold': 1, 'Silver': 2, 'Bronze': 3 } List = [('Bronze', 1), ('Gold', 1), ('Gold', 2)] new_list = sorted(List, key=lambda word: (medals_map[word[0]], word[1])) print new_list
Output:
[('Gold', 1), ('Gold', 2), ('Bronze', 1)]