4 ms·
A more idiomatic way to handle this is to arrange the items in the tuple by sort precedence, then restructure the data in the tuple after the sort. >>> [(b, a)
by rectangletangle 11y ago
A more idiomatic way to handle this is to arrange the items in the tuple by sort precedence, then restructure the data in the tuple after the sort.
>>> [(b, a) for a, b in sorted(((-(x2), x) for x in xrange(10) if 0 == x % 2))]
[(8, -64), (6, -36), (4, -16), (2, -4), (0, 0)]
However, ocasionally you still need a more complex sorting function. So lambdas are still handy, IMO.