Skip to content

Created python script to find the most popular lyric of a song #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Most Popular Lyric/README.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 16 additions & 0 deletions Most Popular Lyric/main.py
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions Most Popular Lyric/song.txt
Original file line number Diff line number Diff line change
@@ -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