I have a list d
that I wish to sort. I sort by the first column first. If its a tie there I then go on to use the second column to sort. Say I want to sort by the first column in ascending order but sort by the second column in descending order. Ascending being the default, using the reverse
key I thought the below should work.
sorted(d,key=lambda x: (x[0],x[1]),reverse=(False,True))
But it does not. It give the following error.
reverse=(False,True))
TypeError: an integer is required (got type tuple)
So if I'm not doing it right how to fix it? Or the way to do this is completely different? Advice on that would be helpful.
My question indeed has some duplication but there are already interesting responses, so I would like to keep it.