Python program that finds most frequent word in a .txt file, Must print word and its count

前端 未结 6 1488
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 23:29

As of right now, I have a function to replace the countChars function,

def countWords(lines):
  wordDict = {}
  for line in lines:
    wordList = lines.split         


        
6条回答
  •  悲哀的现实
    2020-12-08 00:06

     words = ['red', 'green', 'black', 'pink', 'black', 'white', 'black', 
    'eyes','white', 'black', 'orange', 'pink', 'pink', 'red', 'red', 
    'white', 'orange', 'white', "black", 'pink', 'green', 'green', 'pink', 
    'green', 'pink','white', 'orange', "orange", 'red']
    
     from collections import Counter
     counts = Counter(words)
     top_four = counts.most_common(4)
     print(top_four)
    

提交回复
热议问题