-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsongdict.py
80 lines (71 loc) · 2.51 KB
/
songdict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def lyrics_to_frequencies(lyrics):
myDict = {}
for word in lyrics:
if word in myDict:
myDict[word] += 1
else:
myDict[word] = 1
return myDict
sheLovesYou = ['She', 'loves', 'you', 'yeah', 'yeah', 'yeah'
'She', 'loves', 'you', 'yeah', 'yeah', 'yeah',
'She', 'loves', 'you', 'yeah', 'yeah', 'yeah',
'You', 'think', "you've", 'lost', 'your', 'love'
'Well', 'I', 'saw', 'her', 'yesterday-yi-yay',
"It's", 'you', "she's", 'thinking', 'of',
'And', 'she', 'told', 'me', 'what', 'to', 'say-yi-yay',
'She', 'says', 'she', 'loves', 'you',
'And', 'you', 'know', 'that', "can't", 'be', 'bad',
'Yes', 'she', 'loves', 'you',
'And', 'you', 'know', 'you', 'should', 'be', 'glad',
'She', 'said', 'you', 'hurt', 'her', 'so',
'She', 'almost', 'lost', 'her', 'mind',
'And', 'now', 'she', 'says', 'she', 'knows',
"You're", 'not', 'the', 'hurting', 'kind',
'She', 'says', 'she', 'loves', 'you',
'And', 'you', 'know', 'that', "can't", 'be', 'bad',
'Yes', 'she', 'loves', 'you',
'And', 'you', 'know', 'you', 'should', 'be', 'glad',
'Oo', 'she', 'loves', 'you', 'yeah', 'yeah', 'yeah',
'She', 'loves', 'you', 'yeah', 'yeah', 'yeah',
'With', 'a', 'love', 'like', 'that',
'You', 'know', 'you', 'should', 'be', 'glad',
'You', 'know', "it's", 'up', 'to', 'you',
'I', 'think', "it's", 'only', 'fair',
'Pride', 'can', 'hurt', 'you', 'too',
'Apologize', 'to', 'her',
'Because', 'she', 'loves', 'you',
'And', 'you', 'know', 'that', "can't", 'be', 'bad',
'Yes', 'she', 'loves', 'you',
'And', 'you', 'know', 'you', 'should', 'be', 'glad',
'Oo', 'she', 'loves', 'you', 'yeah', 'yeah', 'yeah',
'She', 'loves', 'you', 'yeah', 'yeah', 'yeah',
'With', 'a', 'love', 'like', 'that',
'You', 'know', 'you', 'should', 'be', 'glad',
'With', 'a', 'love', 'like', 'that',
'You', 'know', 'you', 'should', 'be', 'glad',
'With', 'a', 'love', 'like', 'that',
'You', 'know', 'you', 'should', 'be', 'glad',
'Yeah', 'yeah', 'yeah',
'Yeah', 'yeah', 'yeah', 'yeah']
beatles = lyrics_to_frequencies(sheLovesYou)
def most_common_words(freqs):
values = freqs.values()
best = max(values)
words = []
for k in freqs:
if freqs[k] == best:
words.append(k)
return(words, best)
def words_often(freqs, miniTimes):
result = []
done = False
while not done:
temp = most_common_words(freqs)
if temp[1] >= miniTimes:
result.append(temp)
for w in temp[0]:
del(freqs[w])
else:
done = True
return result
print(words_often(beatles, 5))