Sherman IT
12 June 2022
How to order a 2-dimensional list in Python?
https://scripteverything.com/python-2d-list-sort-by-multiple-columns-code-examples-no-imports-one-liners/#:~:text=To%20sort%20a%20two%2Ddimensional,to%20the%20required%20sort%20order.
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]]
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment