Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python sort 2d list different sort order for different columns

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

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

print(data)

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

PREVIOUS NEXT
Code Example
Python :: Python NumPy ndarray flat function Example with 2d array 
Python :: steps in for loop python 
Python :: django content type for model 
Python :: what is attribute in python 
Python :: how stract avery .jpg string in a website python 
Python :: function to perform pairs bootstrap estimates on linear regression parameters 
Python :: python given upper triangle construct symmetric matrix 
Python :: df describe 
Python :: python for loop in range 01 02 
Python :: what is the best ide for python 
Python :: does tuple allow duplicate values in python 
Python :: how to open a file in python 
Python :: symmetrical sum 
Python :: python print exection type 
Python :: sklearn grid search cross validation show progress 
Python :: replace() python 
Python :: Example code of while loop in python 
Python :: unlimited arguments 
Python :: sqlalchemy create engine Oracle 
Python :: email confirmation django 
Python :: what is not equals in python 
Python :: Python NumPy squeeze function Example 
Python :: python parse /etc/resolv.conf 
Python :: dictionary python 
Python :: python get chars among quotation marks 
Python :: pandas to_csv hebrew 
Python :: classes in python 
Python :: python selenium element not interactable while headless 
Python :: python raise exception with custom message 
Python :: Python stop the whole function 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =