Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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]]
Source by scripteverything.com #
 
PREVIOUS NEXT
Tagged: #python #sort #list #sort #order #columns
ADD COMMENT
Topic
Name
7+9 =