As this is homework I skip validation part, but sorting can be alternatively done this way as well (not optimal regarding memory):
>>> tester = {'Afghanistan': {'Gold': 0, 'Silver': 0, 'Bronze': 2, 'Total': 2}, ... 'Albania': {'Gold': 0, 'Silver': 0, 'Bronze': 0, 'Total': 0}, ... 'Algeria': {'Gold': 5, 'Silver': 4, 'Bronze': 8, 'Total': 17}} >>> sorted_by_medals = sorted(tester.items(), key=lambda x: x[1]['Total'], reverse=True) >>> [(i, key, value['Total']) for i, (key, value) in enumerate(sorted_by_medals, start=1)] [(1, 'Algeria', 17), (2, 'Afghanistan', 2), (3, 'Albania', 0)]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.