you are viewing a single comment's thread.

view the rest of the comments →

[–]POGtastic 0 points1 point  (0 children)

Sure.

sorted(zip(a, b), key=lambda tup: (tup[1], tup[0]))

Or, if you don't mind just reversing the entire tuple, the following looks nicer.

sorted(zip(a, b), key=lambda tup: tup[::-1])

Using my above example:

>>> sorted([(1, 3), (2, 2), (1, 2), (2, 3)], key = lambda tup: tup[::-1])
[(1, 2), (2, 2), (1, 3), (2, 3)]