Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Created July 9, 2018 23:40
Show Gist options
  • Save Ram-N/96ea202bb3a540864cba9c2cb919675a to your computer and use it in GitHub Desktop.
Save Ram-N/96ea202bb3a540864cba9c2cb919675a to your computer and use it in GitHub Desktop.
Find Songs given a list of words
['love', 'is', 'in', 'the', 'air']
['mamma', 'mia']
['girls', 'just', 'want', 'to', 'have', 'fun']
--
['love', 'is', 'in', 'the', 'air']
['girls', 'just', 'want', 'to', 'have', 'fun']
['love', 'is']
['music']
['love']
['music']
['love']
--
['we', 'are', 'the', 'champions']
--
import pandas as pd
def print_songs_found(songs_column, clue_words):
for song in songs_column:
try:
songwords = [x.lower() for x in song.split()]
#print(songwords)
if all(word in clue_words for word in songwords):
print(songwords)
except:
pass
def remove_words(clue_words, removelist):
for rw in removelist:
clue_words.remove(rw)
def main():
#Parameters
url = 'https://raw.githubusercontent.com/fivethirtyeight/data/master/classic-rock/classic-rock-song-list.csv'
url2 = 'https://raw.githubusercontent.com/walkerkq/musiclyrics/master/billboard_lyrics_1964-2015.csv'
url3 = 'https://www.maxtv.com.au/top-1000-greatest-songs-of-all-time-3'
songs = pd.read_csv(url, encoding = "ISO-8859-1")
songs2 = pd.read_csv(url2, encoding = "ISO-8859-1")
popular = pd.read_html(url3)
clue_words = [x.lower() for x in """
We Want Champions Farewell To Mamma In Of Jambalaya
Gonsalves The Have Sound Girls Air Sway Que Mia Sera
Are Music Sera The Just Jamaica Fun Love is The Speedy
""".split()]
print(len(clue_words))
list_of_song_lists = [popular[0][1], songs2['Song'], songs['Song Clean']]
for songs_column in list_of_song_lists:
print_songs_found(songs_column, clue_words)
print('--')
if __name__ == '__main__':
main()
#remove_words(clue_words, ['girls', 'just', 'want', 'to', 'have', 'fun'])
#remove_words(clue_words, ['love', 'is', 'in', 'the', 'air'] )
#remove_words(clue_words, ['we', 'are', 'the', 'champions'] )
#remove_words(clue_words, ['the', 'sound', 'of', 'music'] )
#remove_words(clue_words, ['speedy', 'gonsalves'] )
#remove_words(clue_words, ['que', 'sera', 'sera'] )
#remove_words(clue_words, ['mamma', 'mia'] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment