You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
withopen(input("Please enter file name: "), 'r') asf:
4
+
forlineinf:
5
+
words=line.lower().split() #Divides line into words
6
+
forwordinwords:
7
+
ifwordnotinwordsTallied: #New Word
8
+
iflen(word) >=4: #Adds new word to dictionary if longer than 3 letters
9
+
wordsTallied[word] =1
10
+
else: #Repeated word
11
+
wordsTallied[word] +=1#Updates number of times word appears
12
+
f.closed
13
+
14
+
maxWord=max(wordsTallied, key=wordsTallied.get) #Gets the most lyric word of song
15
+
maxCount=wordsTallied[maxWord] #Gets number of times the lyric appears
16
+
print("\n"+"The most popular lyric is: '"+maxWord+"' \nIt appears "+str(maxCount) +" times in the song" ) #Prints most popular lyric and the number of occurences in the song
0 commit comments