我想显示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),
答案 0 :(得分:2)
一种方法是将sorted
与key
参数一起使用:
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)]