from operator import itemgetter
MY_SORTED_TUPLE = tuple(sorted(MY_TUPLE, key=itemgetter(1)))
or without itemgetter
:
MY_SORTED_TUPLE = tuple(sorted(MY_TUPLE, key=lambda item: item[1]))
More Related Contents:
- How to sort a list/tuple of lists/tuples by the element at a given index?
- How to sort a list with two keys but one in reverse order?
- Sort tuples based on second parameter
- Sort a list of tuples depending on two elements [duplicate]
- Find partial tuple in list of tuple
- How to merge lists into a list of tuples?
- What is the syntax rule for having trailing commas in tuple definitions?
- Pythonic way to check if a list is sorted or not
- pandas groupby sort within groups
- Two variables in Python have same id, but not lists or tuples
- How to sort alpha numeric set in python
- Sorting text file by using Python
- Append to a list defined in a tuple – is it a bug? [duplicate]
- sorting by a custom list in pandas
- List of tuples to dictionary [duplicate]
- case-insensitive list sorting, without lowercasing the result?
- Sort a pandas dataframe series by month name
- How to find the maximum value in a list of tuples? [duplicate]
- python tuple to dict
- converting string to tuple
- Why do we need tuples in Python (or any immutable data type)?
- What does *tuple and **dict mean in Python? [duplicate]
- How to sort with lambda in Python
- Why does adding a trailing comma after an expression create a tuple?
- How to sort Counter by value? – python
- Retrieve the two highest item from a list containing 100,000 integers
- How does str.startswith really work?
- How to use ast.literal_eval in a pandas dataframe and handle exceptions
- python tuple is immutable – so why can I add elements to it
- How to sort a list of dictionaries by a value of the dictionary in Python?