How to find the most frequent word in a given a list of strings with Python

1 Answer

0 votes
from collections import defaultdict

lst = ["python php", "java c c++", "python rust", "go python"]

dic = defaultdict(int)

for s in lst:
   for word in s.split():
      dic[word] += 1

result = max(dic, key = dic.get)

print(result)



'''
run:

python

'''

 



answered May 28, 2023 by avibootz
...