L = [['a',1], ['a',2], ['a',3], ['b',1], ['b',2], ['b',3]]
L.sort(key=lambda k: (k[0], -k[1]), reverse=True)
L
now contains:
[['b', 1], ['b', 2], ['b', 3], ['a', 1], ['a', 2], ['a', 3]]
More Related Contents:
- How to keep keys/values in same order as declared?
- How can I sort a dictionary by key?
- How to sort a list/tuple of lists/tuples by the element at a given index?
- How to correctly sort a string with a number inside? [duplicate]
- Pythonic way to check if a list is sorted or not
- How to sort a list of tuples according to another list
- How to sort objects by multiple keys?
- pandas groupby, then sort within groups
- Why does my Pandas DataFrame not display new order using `sort_values`?
- How to use a custom comparison function in Python 3?
- How can I get 2.x-like sorting behaviour in Python 3.x?
- Accessing the list while being sorted
- Does python have a sorted list?
- Python sorting by multiple criteria
- Sort a part of a list in place
- How to sort IP addresses stored in dictionary in Python?
- Find elements of array one nearest to elements of array two
- How to sort with lambda in Python
- How to sort Counter by value? – python
- Sort a list of tuples depending on two elements [duplicate]
- How to sort a list by length of string followed by reverse alphabetical order? [duplicate]
- Sort a list with a custom order in Python
- Python Sort One List According to Another List
- Python: How to sort a list of dictionaries by several values?
- Using a comparator function to sort
- How to sort a list of x-y coordinates
- argsort for a multidimensional ndarray
- Nested lambda statements when sorting lists
- Searching a sorted list? [closed]
- Sorting a pandas series