【发布时间】:2014-07-18 02:29:13
【问题描述】:
我正在尝试使用以下代码打印前 10 个常用词。但是,它不起作用。关于如何修复它的任何想法?
def reducer_count_words(self, word, counts):
# send all (num_occurrences, word) pairs to the same reducer.
# num_occurrences is so we can easily use Python's max() function.
yield None, (sum(counts), word)
# discard the key; it is just None
def reducer_find_max_10_words(self, _, word_count_pairs):
# each item of word_count_pairs is (count, word),
# so yielding one results in key=counts, value=word
tmp = sorted(word_count_pairs)[0:10]
yield tmp
【问题讨论】:
-
@Veedrac:更类似于这个问题:stackoverflow.com/questions/3121979/…
-
@Leftium 我强烈不同意你对这个问题的解释。此外,到底是如何“它不起作用。关于如何解决它的任何想法?”获得支持?
-
@Veedrac:我的解释是基于问题标题和提问者对其他答案的回答。
-
@Leftium 我坚持我的观点,但我并不真正关心这种质量问题。