python如何对列表[(a, b),(a, b)]进行排序?
aalist = [(1184, 862), (1034, 871), (968, 848), (910, 834), (716, 832), (594, 872), (594, 872), (855, 834), (796, 837), (1330, 827), (1330, 827), (623, 834)]
python如何对列表进行排序
[(a, b),(a, b)]
对前面的a 按照大小进行排序
回答:
➜ ~ ipythonPython 3.9.12 (main, Apr 5 2022, 01:53:17)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.2.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: aalist = [(1184, 862), (1034, 871), (968, 848), (910, 834), (716, 832), (594, 872), (594, 872), (855, 834), (796, 837), (1330, 827), (1330, 827), (623, 834)]
...:
In [2]: sorted(aalist, key=lambda _: _[0])
Out[2]:
[(594, 872),
(594, 872),
(623, 834),
(716, 832),
(796, 837),
(855, 834),
(910, 834),
(968, 848),
(1034, 871),
(1184, 862),
(1330, 827),
(1330, 827)]
以上是 python如何对列表[(a, b),(a, b)]进行排序? 的全部内容, 来源链接: utcz.com/p/938612.html