Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python sort 2d list

data = [['ABC', 12, 3, 100],
        ['DEF', 10, 5, 200],
        ['GHI', 13, 3, 1000]]

data.sort(key=lambda row: (row[2], row[3]), reverse=True)

print(data)

# [['DEF', 10, 5, 200], ['GHI', 13, 3, 1000], ['ABC', 12, 3, 100]]
Comment

sort 2d list python

>>> sorted(li,key=lambda l:l[1])
[[1, 0.23], [5, 0.27], [4, 0.31], [2, 0.39]]
Comment

PREVIOUS NEXT
Code Example
Python :: python initialize dictionary with lists 
Python :: python check list contains another list 
Python :: pandas read csv unnamed 0 
Python :: pandas to dict by row 
Python :: how to make python speak 
Python :: plotly reverse y axis 
Python :: pycharm remove not in use imports 
Python :: python random choice in list 
Python :: python ls 
Python :: python print stderr 
Python :: python datetime last day of month 
Python :: django admin image 
Python :: dot product python 
Python :: forbidden (csrf cookie not set.) django rest framework 
Python :: openpyxl get last non empty row 
Python :: python not null 
Python :: download pdf using python 
Python :: convert two numpy array to pandas dataframe 
Python :: Parameter Grid python 
Python :: how to make a forever loop in python 
Python :: how to install python 2 
Python :: position of legend matplotlib 
Python :: how to record the steps of mouse and play the steps using python 
Python :: print fibonacci series in reverse in python 
Python :: python range backward 
Python :: enumerate in python 
Python :: how to remove empty elements in a list python 
Python :: how to print variables in a string python 
Python :: urlencode python 
Python :: what is my python working directory 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =