Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
lst = [(1,(1,3,5)), (5,(2,3,4)),(3,(2,3,4))]
I want to sort by the first value, descending order.
just like this:
sorted(lst, reverse=True)
Add a comment
Sort in place? Use:
lst.sort(reverse=True)
import operator sorted(lst, reverse=True, key=operator.itemgetter(0))
sorted(list, reverse=True, key=lambda x: x[0])
Note also that "list" isn't a great name for your list because it's the built-in list type.
You can sort like this.
sorted(lst, key=lambda a: a[0], reverse=True)
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.