Skip to content

Instantly share code, notes, and snippets.

View anitaokoh's full-sized avatar

Anita Okoh anitaokoh

View GitHub Profile
#the lyrics of the song (perfect by Ed Sheeran) has been cleaned out
perfect_lyrics = "I found a love for me darling just dive right in and follow my lead\
well I found a girl beautiful and sweet I never knew you were the someone waiting for me\
because we were just kids when we fell in love not knowing what it was I will not give you up this time\
but darling, just kiss me slow, your heart is all I own and in your eyes you are holding mine\
baby, I am dancing in the dark with you between my arms barefoot on the grass, listening to our favorite song\
when you said you looked a mess, I whispered underneath my breath but you heard it, darling, you look perfect tonight\
well I found a woman, stronger than anyone I know she shares my dreams, I hope that someday I will share her home\
I found a love, to carry more than just my secrets to carry love, to carry children of our own\
"I found a love for me darling just dive right in and follow my lead\
well I found a girl beautiful and sweet I never knew you were the someone waiting for me\
because we were just kids when we fell in love not knowing what it was I will not give you up this time\
but darling, just kiss me slow, your heart is all I own and in your eyes you are holding mine\
baby, I am dancing in the dark with you between my arms barefoot on the grass, listening to our favorite song\
when you said you looked a mess, I whispered underneath my breath but you heard it, darling, you look perfect tonight\
well I found a woman, stronger than anyone I know she shares my dreams, I hope that someday I will share her home\
I found a love, to carry more than just my secrets to carry love, to carry children of our own\
we are still kids, but we are so in love fighting against all odds I know we will be alright this time\
darling, just hold my hand be my girl, I will be your man I see my future in your eyes\
#To seperate each word to create a list
split_lyrics = perfect_lyrics.split(' ')
print(split_lyrics)
# To seperate the unique words
unique_words = set(split_lyrics)
print(unique_words)
len(split_lyrics) #number of words in the whole lyrics
len(unique_words) # number of unique words
# To count the number of times the unique words appear , first in the unique_word list
word_dict = {} #An empty dictionary
for word in unique_words:
word_dict[word] = 0
print(word_dict)
# then in the whole song
for word in split_lyrics:
word_dict[word] = word_dict[word] + 1
print(word_dict)
# To sort the value of the words in descending order
sort_dict = sorted(word_dict.items(),key = lambda t: t[1], reverse =True)
print(sort_dict)
# To slice the list to extract the top 10 repeated words
toplist = sort_dict[0:10]
toplist