How to sort a two-dimensional list (list of lists) by rows in Python

1 Answer

0 votes
list2D = [
    [9, 7, 8, 4],
    [3, 1, 2, 0],
    [6, 4, 5, 3]
]
 
# Sorting rows
list2D.sort(key=lambda x: x[1])
 
print(list2D)
 
 
 
'''
run:
 
[[3, 1, 2, 0], [6, 4, 5, 3], [9, 7, 8, 4]]
 
'''

 



answered Mar 16 by avibootz
edited Mar 16 by avibootz
...