Skip to content

Commit 90d5782

Browse files
authored
Merge pull request larymak#129 from asikri-umd/main
Created python script to find the most popular lyric of a song
2 parents 3f3eb31 + ba6956b commit 90d5782

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

Most Popular Lyric/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Most Popular Lyric
2+
This Python script will find and return the most frequently appearing lyric of a song.
3+
In the case where there is more than one lyric, it will return the lyric that appears first in the song.
4+
5+
This script accepts song lyrics only as *.txt* files.
6+
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.
7+
8+
Make sure to input the filename after running the script to return results.

Most Popular Lyric/main.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
wordsTallied = {}
3+
with open(input("Please enter file name: "), 'r') as f:
4+
for line in f:
5+
words = line.lower().split() #Divides line into words
6+
for word in words:
7+
if word not in wordsTallied: #New Word
8+
if len(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

Most Popular Lyric/song.txt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Just a small town girl
2+
Livin' in a lonely world
3+
She took the midnight train goin' anywhere
4+
Just a city boy
5+
Born and raised in South Detroit
6+
He took the midnight train goin' anywhere
7+
A singer in a smokey room
8+
The smell of wine and cheap perfume
9+
For a smile they can share the night
10+
It goes on and on, and on, and on
11+
Strangers, waitin'
12+
Up and down the boulevard
13+
Their shadows
14+
Searchin' in the night
15+
Streetlights, people
16+
Livin' just to find emotion
17+
Hidin' somewhere in the night
18+
Workin' hard to get my fill
19+
Everybody wants a thrill
20+
Payin' anything to roll the dice
21+
Just one more time
22+
Some will win
23+
Some will lose
24+
Some were born to sing the blues
25+
Oh, the movie never ends
26+
It goes on and on, and on, and on
27+
Strangers waitin'
28+
Up and down the boulevard
29+
Their shadows
30+
Searchin' in the night
31+
Streetlights, people
32+
Livin' just to find emotion
33+
Hidin' somewhere in the night
34+
Don't stop believin'
35+
Hold on to that feelin'
36+
Streetlight, people
37+
Don't stop, believin'
38+
Hold on
39+
Streetlights, people
40+
Don't stop believin'
41+
Hold on to that feelin'
42+
Streetlight, people

0 commit comments

Comments
 (0)