How to sort each row from a two-dimensional list (list of lists) in Python

1 Answer

0 votes
list2D = [
    [3, 1, 2, 0],
    [9, 7, 8, 4],
    [6, 4, 5, 3]
]
 
# Sorting each row
list2D = [sorted(row) for row in list2D]
 
print(list2D)
 
 
 
'''
run:
 
[[0, 1, 2, 3], [4, 7, 8, 9], [3, 4, 5, 6]]
 
'''

 



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