I have a similar question to this one but instead my tuple contains lists, as follows:
mytuple = (
["tomato", 3],
["say", 2],
["say", 5],
["I", 4],
["you", 1],
["tomato", 6],
)
What’s the most efficient way of sorting this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can get a sorted tuple easy enough:
This will sort based on the items in the list. If the first two match, it compares the second, etc.
If you have a different criteria, you can provide a comparison function.
Updated: As a commenter noted, this returns a list. You can get another tuple like so: