I need to reorder a Python list according to the second element of embedded lists:
So this:
[[1, 'A'], [2, 'B'], [3, 'B'], [4, 'A'], [5, 'C']]
Should turn into that:
[[1, 'A'], [4, 'A'], [2, 'B'], [3, 'B'], [5, 'C']]
I am struggling with this piece of code right now:
values = set(map(lambda x:x[1], l))
l = [[y[0] for y in l if y[1]==x] for x in values]
What the most straightforward way to accomplish this?