From 177bfcfdcef16faa60dd34391f62ba0871a327f6 Mon Sep 17 00:00:00 2001 From: Ambika Date: Fri, 21 Jan 2022 21:03:13 -0500 Subject: [PATCH 1/5] Most Popular Lyric --- Most Popular Lyric/README.md | 4 ++++ Most Popular Lyric/main.py | 18 ++++++++++++++++ Most Popular Lyric/song.txt | 42 ++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 Most Popular Lyric/README.md create mode 100644 Most Popular Lyric/main.py create mode 100644 Most Popular Lyric/song.txt diff --git a/Most Popular Lyric/README.md b/Most Popular Lyric/README.md new file mode 100644 index 00000000..ebf19e82 --- /dev/null +++ b/Most Popular Lyric/README.md @@ -0,0 +1,4 @@ +### Most Popular Lyric +This Python script will find the lyric that appears the most times in a *txt* file containing lyrics to a song. +A sample file is provided named song.txt and contains the lyrics to Don't Stop Believin' by Journey. +You can add your own file to the directory, make sure to add the filename as input 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..59a7e8cf --- /dev/null +++ b/Most Popular Lyric/main.py @@ -0,0 +1,18 @@ + +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 + +# print(findMostPopularLyric(song.txt)) 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 From f3992b609e2f2a30b5bb1e8443c92a0da0b39ec2 Mon Sep 17 00:00:00 2001 From: Ambika Sikri <50977414+asikri-umd@users.noreply.github.com> Date: Fri, 21 Jan 2022 21:04:13 -0500 Subject: [PATCH 2/5] Update main.py --- Most Popular Lyric/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Most Popular Lyric/main.py b/Most Popular Lyric/main.py index 59a7e8cf..674a56a0 100644 --- a/Most Popular Lyric/main.py +++ b/Most Popular Lyric/main.py @@ -14,5 +14,3 @@ 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 - -# print(findMostPopularLyric(song.txt)) From 955d7d78c26cdb103210ce97b53c4c7bb4b01347 Mon Sep 17 00:00:00 2001 From: Ambika Sikri <50977414+asikri-umd@users.noreply.github.com> Date: Fri, 21 Jan 2022 21:04:55 -0500 Subject: [PATCH 3/5] Update README.md --- Most Popular Lyric/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Most Popular Lyric/README.md b/Most Popular Lyric/README.md index ebf19e82..c9ce8aac 100644 --- a/Most Popular Lyric/README.md +++ b/Most Popular Lyric/README.md @@ -1,4 +1,6 @@ ### Most Popular Lyric This Python script will find the lyric that appears the most times in a *txt* file containing lyrics to a song. + A sample file is provided named song.txt and contains the lyrics to Don't Stop Believin' by Journey. -You can add your own file to the directory, make sure to add the filename as input after running the script to return results. + +You can add your own file to the directory, but make sure to add the filename as input after running the script to return results. From dd582eaa20f5499c9b11460593eb0d0208e77767 Mon Sep 17 00:00:00 2001 From: Ambika Sikri <50977414+asikri-umd@users.noreply.github.com> Date: Fri, 21 Jan 2022 21:09:48 -0500 Subject: [PATCH 4/5] Updated ReadMe.md --- Most Popular Lyric/README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Most Popular Lyric/README.md b/Most Popular Lyric/README.md index c9ce8aac..e76fc66a 100644 --- a/Most Popular Lyric/README.md +++ b/Most Popular Lyric/README.md @@ -1,6 +1,8 @@ ### Most Popular Lyric -This Python script will find the lyric that appears the most times in a *txt* file containing lyrics to a song. +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. -A sample file is provided named song.txt and contains the lyrics to Don't Stop Believin' by Journey. +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. -You can add your own file to the directory, but make sure to add the filename as input after running the script to return results. +Make sure to input the filename after running the script to return results. From ba6956bb3631d6d29359652d105f07bf1e2378f7 Mon Sep 17 00:00:00 2001 From: Ambika Sikri <50977414+asikri-umd@users.noreply.github.com> Date: Fri, 21 Jan 2022 21:09:56 -0500 Subject: [PATCH 5/5] Update README.md --- Most Popular Lyric/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Most Popular Lyric/README.md b/Most Popular Lyric/README.md index e76fc66a..90360d0c 100644 --- a/Most Popular Lyric/README.md +++ b/Most Popular Lyric/README.md @@ -1,4 +1,4 @@ -### Most Popular Lyric +## 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.