diff --git a/Most Popular Lyric/README.md b/Most Popular Lyric/README.md new file mode 100644 index 00000000..90360d0c --- /dev/null +++ b/Most Popular Lyric/README.md @@ -0,0 +1,8 @@ +## Most Popular Lyric +This Python script will find and return the most frequently appearing lyric of a song. +In the case where there is more than one lyric, it will return the lyric that appears first in the song. + +This script accepts song lyrics only as *.txt* files. +A sample file is provided named *song.txt* that contains the lyrics to Don't Stop Believin' by Journey, but feel free to add your own *.txt* file to the direcctory. + +Make sure to input the filename after running the script to return results. diff --git a/Most Popular Lyric/main.py b/Most Popular Lyric/main.py new file mode 100644 index 00000000..674a56a0 --- /dev/null +++ b/Most Popular Lyric/main.py @@ -0,0 +1,16 @@ + +wordsTallied = {} +with open(input("Please enter file name: "), 'r') as f: + for line in f: + words = line.lower().split() #Divides line into words + for word in words: + if word not in wordsTallied: #New Word + if len(word) >= 4: #Adds new word to dictionary if longer than 3 letters + wordsTallied[word] = 1 + else: #Repeated word + wordsTallied[word] += 1 #Updates number of times word appears + f.closed + +maxWord = max(wordsTallied, key=wordsTallied.get) #Gets the most lyric word of song +maxCount = wordsTallied[maxWord] #Gets number of times the lyric appears +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 diff --git a/Most Popular Lyric/song.txt b/Most Popular Lyric/song.txt new file mode 100644 index 00000000..33fef1eb --- /dev/null +++ b/Most Popular Lyric/song.txt @@ -0,0 +1,42 @@ +Just a small town girl +Livin' in a lonely world +She took the midnight train goin' anywhere +Just a city boy +Born and raised in South Detroit +He took the midnight train goin' anywhere +A singer in a smokey room +The smell of wine and cheap perfume +For a smile they can share the night +It goes on and on, and on, and on +Strangers, waitin' +Up and down the boulevard +Their shadows +Searchin' in the night +Streetlights, people +Livin' just to find emotion +Hidin' somewhere in the night +Workin' hard to get my fill +Everybody wants a thrill +Payin' anything to roll the dice +Just one more time +Some will win +Some will lose +Some were born to sing the blues +Oh, the movie never ends +It goes on and on, and on, and on +Strangers waitin' +Up and down the boulevard +Their shadows +Searchin' in the night +Streetlights, people +Livin' just to find emotion +Hidin' somewhere in the night +Don't stop believin' +Hold on to that feelin' +Streetlight, people +Don't stop, believin' +Hold on +Streetlights, people +Don't stop believin' +Hold on to that feelin' +Streetlight, people \ No newline at end of file