15/29
Part 4 of 6 · Sorting and the latest entryLearn and do

Sort explicitly, every time

The scans return their fields in a stated order, and ties are where answers go wrong.

Give sorted a tuple with every tie-break in it

balances = {"zoe": 40, "ana": 75, "ben": 10}
print(sorted(balances.items()))
print(sorted(balances.items(), key=lambda row: (-row[1], row[0])))
Predict

key=lambda row: (-row[1], row[0]) on zoe 40, ana 75 and ben 10. What order comes out?

Pick one to see what it prints.
Pick an answer above to see the rest