You can use a lambda:
>>> li=[[1, 0.23],
... [2, 0.39],
... [4, 0.31],
... [5, 0.27]]
>>> sorted(li,key=lambda l:l[1], reverse=True)
[[2, 0.39], [4, 0.31], [5, 0.27], [1, 0.23]]
Or the other way:
>>> sorted(li,key=lambda l:l[1])
[[1, 0.23], [5, 0.27], [4, 0.31], [2, 0.39]]
More Related Contents:
- Sort multidimensional array based on 2nd element of the subarray
- Sorting list based on values from another list
- How to sort a list/tuple of lists/tuples by the element at a given index?
- Matrix Transpose in Python [duplicate]
- Pythonic way to check if a list is sorted or not
- How to define a two-dimensional array?
- How do I make a flat list out of a list of lists?
- How to sort a list of tuples according to another list
- Sorting Python list based on the length of the string
- How to sort and remove duplicates from Python list? [duplicate]
- case-insensitive list sorting, without lowercasing the result?
- Accessing the list while being sorted
- List sorting with multiple attributes and mixed order
- Sorting a dictionary with lists as values, according to an element from the list
- django – convert a list back to a queryset [duplicate]
- Python data structure sort list alphabetically
- Sort list of strings by a part of the string
- Efficient method to calculate the rank vector of a list in Python
- Python .sort() not working as expected
- How to sort a list of objects based on an attribute of the objects in descending order?
- How do I sort a list of objects based on an attribute of the objects?
- How to sort a list of strings in reverse order without using reverse=True parameter?
- Python Sort One List According to Another List
- Converting List Comprehensions to For Loops in Python
- Sort list while pushing None values to the end
- Retrieve the two highest item from a list containing 100,000 integers
- How to find the max number(s) in a list with tied numbers
- How can I sort a list, according to where its elements appear in another list?
- How can I turn a flat list into a 2D array in python?
- How to sort a list of dictionaries by a value of the dictionary in Python?