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
Python 元组的升序排序列表_Python_Python 3.x_Sorting_Tuples - Fatal编程技术网

Python 元组的升序排序列表

Python 元组的升序排序列表,python,python-3.x,sorting,tuples,Python,Python 3.x,Sorting,Tuples,我想显示ID和标记,并按最上面的标记按升序排序 word_counts = word_tuple.reduceByKey(lambda total, count: total + count) word_counts.take(30) [('id,tags', 1), ('"16586898","', 1), ('javascript', 3276), ('data-structures', 48), ('documentation', 1153), ('data-visualiza

我想显示ID和标记,并按最上面的标记按升序排序

word_counts = word_tuple.reduceByKey(lambda total, count: total + count)
word_counts.take(30)

[('id,tags', 1),
 ('"16586898","', 1),
 ('javascript', 3276),
 ('data-structures', 48),
 ('documentation', 1153),
 ('data-visualization', 10),
 ('"', 27109),
 ('"1828522","', 1),
 ('api', 634),
 ('console', 19),
 ('installation', 17),
 ('glassfish', 5),
 ('admin', 3),
 ('"25883048","', 1),
 ('regex', 500),
 ('bash', 375),
 ('sed', 56),
 ('"1879493","', 1),

一种方法是将
排序
参数一起使用:

sorted(lst, key=lambda x: x[1])

# [('id,tags', 1),
#  ('"16586898","', 1),
#  ('"1828522","', 1),
#  ('"25883048","', 1),
#  ('"1879493","', 1),
#  ('admin', 3),
#  ('glassfish', 5),
#  ('data-visualization', 10),
#  ('installation', 17),
#  ('console', 19),
#  ('data-structures', 48),
#  ('sed', 56),
#  ('bash', 375),
#  ('regex', 500),
#  ('api', 634),
#  ('documentation', 1153),
#  ('javascript', 3276),
#  ('"', 27109)]

你能解释前两行吗?它们不是本地Python。下面的答案之一有帮助吗?如果是这样,请随意接受,或提出问题以澄清。