回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我是python新手,我试图在歌词中返回最多50个常用词,我有一个问题,我真的不明白为什么会发生这种情况</p>
<p>代码中的名称“歌词”是来自文本文件的歌词字符串。循环的每一次迭代都是不同的歌词串,我需要将它们包含在歌曲中显示的单词总数中</p>
<p>如果有人知道问题出在哪里,并能提供帮助,那就太好了</p>
<blockquote>
<p>my output is not with words is in characters: "[(' ', 46), ('o', 24), ('e', 23), ('n', 15), ('t', 15), ('h', 12), ('a', 12), ('w', 8), ('r', 8), ('s', 8), ('\n', 7), ('f', 7), ('d', 6), ('u', 5), ('y', 5), ('m', 5), ('I', 4)..." and i need to get something like: ("the", 555), ("you", 365)... without include white spaces and \n</p>
</blockquote>
<pre><code> count = {}
for songs in the_dict.values():
songs = songs[0]
for lyrics in songs.values():
lyrics = lyrics[2]
count = Counter(lyrics)
return count.most_common(50)
</code></pre>