orders = [('Pune', 200), ('Agra', 300), ('Pune', 900)]; two_pass(orders)[('Agra', 300), ('Pune', 900), ('Pune', 200)]Within Pune, 900 precedes 200 because the amount-descending pass ran first and stability preserved it.
Sort by amount descending FIRST, then by city ascending.
The second sort will not disturb equal-city groups.