Skip to content

Instantly share code, notes, and snippets.

@norbinsh
Created May 22, 2019 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norbinsh/0761bd051b2a7d6318efa317f637a9e5 to your computer and use it in GitHub Desktop.
Save norbinsh/0761bd051b2a7d6318efa317f637a9e5 to your computer and use it in GitHub Desktop.
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