dict.items() gives you this: [ ("KOR", [4, 6, 3]), ("JPN", [5, 2, 1]), ... convert to this format: [ ("KOR", 4,6,3), ("JPN", 5, 2, 1), ... 4 sorts with itemgetter: countries bronze reversed silver reversed gold reversed def mystery(num) if num > 8: return 2 else: return mystery(num+2) + 3 mystery(1) M(1) = M(3) + 3 = 11 + 3 = 14 M(3) = M(5) + 3 = 8 + 3 = 11 M(5) = M(7) + 3 = 5 + 3 = 8 M(7) = M(9) + 3 = 2 + 3 = 5 M(9) = 2 A few of the RegEx's I typed in: ^z* ^z+ ^e.*on$ ^e.*nd$ ^e.*i(ng)?$