Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def count_common_words(text):
- word_counter = {}
- most_populr_word = tuple() # (word, count)
- for word in text.split():
- word_counter.setdefault(word, 0)
- word_counter[word] += 1
- if most_populr_word:
- if word_counter.get(word) > most_populr_word[1]:
- most_populr_word = (word, word_counter[word])
- else:
- most_populr_word = (word, word_counter[word])
- print(sorted(word_counter.items(), key=lambda kv: kv[1], reverse=True))[:11]
- print(most_populr_word[0])
- count_common_words(text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement