Created
May 22, 2019 21:48
-
-
Save norbinsh/0761bd051b2a7d6318efa317f637a9e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import operator | |
from collections import defaultdict | |
NONSENSE = { | |
'SONG_A': 'love you baby much love i you', | |
'SONG_B': 'monitors could be the real monitors of the world', | |
'SONG_C': 'the world is a big world of worlds on earth, world' | |
} | |
def word_detector(songs_data): | |
words = defaultdict(dict) | |
for value in songs_data.values(): | |
for word in value.split(' '): | |
if words.get(word): | |
words[word] += 1 | |
else: | |
words[word] = 1 | |
return sorted({k:v for k,v in words.items() if v > 1}.items(), key=operator.itemgetter(1))[-5:] | |
print(word_detector(NONSENSE)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment