I am trying to implement a procedure that involves coupled element counts and sorting. However, I got stuck.
Here is an example:
olimpic=[['Russia', 'bronze', 'basketball_male'],
['China', 'gold', 'soccer_female'],
['China', 'silver', 'judo_male_100kg'],
['Australia', 'gold', 'surf_male'],
['Cuba', 'gold', 'gymnastics_solo_female'],
['Russia', 'silver', 'karate_female_60kg'],
['China', 'silver', 'voleyball_female']]
This is what I've already done:
short=[]
for i in range(len(olimpic)):
short.append([olimpic[i][0],olimpic[i][1]])
countrySort=sorted(short, key=lambda element: (element, element[1]))
print (countrySort)
My current output is:
[['Australia', 'gold'],
['China', 'gold'],
['China', 'silver'],
['China', 'silver'],
['Cuba', 'gold'],
['Russia', 'bronze'],
['Russia', 'silver']]
However, I have to do other three steps:
Make a paired count of the country and type of medal
Sort according the number of type of medal, keeping in mind that; gold > silver > bronze regardless the number of medals in the lower levels.
When two or more countries have exactly the same number of types of medals, sort them by their names
the output should be like this (a list of tuples):
Rank of the countries:
(1, 2, 0, 'China')
(1, 0, 0, 'Australia')
(1, 0, 0, 'Cuba')
(0, 1, 1, 'Russia')