删除最终输出

时间:2016-04-10 05:54:12

标签: python list output counter frequency

嗨所以我正在编写一个函数,它接收包含文本的文件并返回文件中最常用的单词。我目前的代码如下:

import collections

def approximate_song(filename):
    text = open(filename).read()
    counts = collections.Counter(text.lower().split())

return [elem for elem, _ in sorted(counts.most_common(), key=lambda
                                   x: (-x[1], x[0]))[:1]]

这将返回最常用的单词。但是,它会以['word here']格式返回它,当它应该返回为'word here'时。 (不在方括号中,而是在s中单独使用)。

非常感谢任何帮助!

0 个答案:

没有答案
相关问题