What I am trying to do is sort a list of tuples, that the first cell in the tuple can be many nested tuples, but the second cell is always a int value,
My code:
t = [('d',2), ('b', 1), (('a', 'c'), 2)]
sorted(t, key=lambda x: x[1], reverse=True)
But this is not working, the last nested tuple stays in the end. any ideas?
[('d', 2), (('a', 'c'), 2), ('b', 1)]. Or did you expect(('a', 'c'), 2)to be sorted first?sorted()returns a new, sorted list. If you wantedtto be sorted in-place, callt.sort()instead.