Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 使用此表单的元素(';string';number)对列表进行排序_Sorting_Python 3.x - Fatal编程技术网

Sorting 使用此表单的元素(';string';number)对列表进行排序

Sorting 使用此表单的元素(';string';number)对列表进行排序,sorting,python-3.x,Sorting,Python 3.x,我想在此表单中对列表进行排序: [('Initial value problem', 0.0), ('Duns Scotus', 0.0), ('Open front unrounded vowel', 0.0), ('Android version history', 0.0001), ('Research ethics', 0.0001), ('Music technology', 0.0), ('Karl Bechert', 0.0001), ('Motion

我想在此表单中对列表进行排序:

[('Initial value problem', 0.0), 
 ('Duns Scotus', 0.0), 
 ('Open front unrounded vowel', 0.0), 
 ('Android version history', 0.0001), 
 ('Research ethics', 0.0001), 
 ('Music technology', 0.0), 
 ('Karl Bechert', 0.0001), 
 ('Motion (physics)', 0.0001), 
 ('Karl Friedrich Burdach', 0.0)]
我想根据每个元素中的数字对这个列表进行排序。
谢谢。

只需通过设置
参数对每个项目的第二个元素排序即可

>>> l = [('Initial value problem', 0.0), 
     ('Duns Scotus', 0.0), 
     ('Open front unrounded vowel', 0.0), 
     ('Android version history', 0.0001), 
     ('Research ethics', 0.0001), 
     ('Music technology', 0.0), 
     ('Karl Bechert', 0.0001), 
     ('Motion (physics)', 0.0001), 
     ('Karl Friedrich Burdach', 0.0)]

>>> print sorted(l, key=lambda x: x[1])

[('Initial value problem', 0.0),
 ('Duns Scotus', 0.0),
 ('Open front unrounded vowel', 0.0),
 ('Music technology', 0.0),
 ('Karl Friedrich Burdach', 0.0),
 ('Android version history', 0.0001),
 ('Research ethics', 0.0001),
 ('Karl Bechert', 0.0001),
 ('Motion (physics)', 0.0001)]

如果希望它们按相反的顺序排列,也可以在调用
sorted()

@mins中设置
reverse=True
参数。因为一开始我不知道从哪里开始解决这个问题。可能是@mins的副本谢谢你告诉我这个。