In: Computer Science
PYTHON PROGRAM
Requirements:
1. Create an empty directory a variable named song_search
2. Repeatedly prompt the user to enter either the title of a song or enter nothing if they have no more songs to enter
3. For each song title entered by the user, split the song title into words by using the split function and splitting on a space. For each word from each song title, ensure the song_search dictionary has a entry with that word as the key and a list (initially empty) as the value
4. Also for each song title entered by the user and each word from each song title, insert the full song title into the list inside the song_search dictionary associated with each of the words from the song. For example, the contents of the song_search dictionary after the user would have entered the song titles Crazy in Love and What is Love:
song_search = {’Crazy’ : [ ’Crazy in Love’ ],’in’ : [ ’Crazy in Love’ ],’Love’ : [ ’Crazy in Love’, ’What is Love’ ],’What’ : [ ’What is Love’ ],’is’ : [ ’What is Love’ ]}
Once the user has finished entering song titles, repeatedly ask the user if they want to look up a song by keyword until they say no. If they respond yes prompt them for a keyword and print all the song titles containing that word by looking up the value in the song_search dictionary using the key word as the key
5. If the keyword the user entered is in more than one song title, print each song title on a separate line preceeded by a number beginning with one and increasing by one for each song
6. If the keyword the user entered is in none of the song titles print the message Keyword not found in any song titles
song_search={}#SONG DICTIONARY
#SONG INSERTION IN DICTIONARY
n=int(input("Press 1 to enter more songs and 0 to exit : "))
while(n):
song=input("Enter song name : ").split(" ")
for i in range(0,len(song)):
s=[]
s[0:len(song)]=[' '.join(song[0:len(song)])]#JOINS THE WORDS OF
LIST ' song' AS SONG NAME.
if song[i] in song_search.keys():#IF KEY ALREADY EXIST ADDING THE
SONG IN VALUE OF KEY
s=s+song_search.get(song[i])
song_search.update({song[i]:s})
else:
song_search.update({song[i]:s})
n=int(input("Press 1 to enter more songs and 0 to exit : "))
#SEARCH SONG
n=int(input("\npress 1 to search for a song and 0 to exit :
"))
while(n):
song=input("Enter the keyword : ")
if song in song_search.keys():
for i in range(0,len(song_search[song])):
print(i+1," : ",song_search[song][i])
else:
print("key word not found.\n")
n=int(input("press 1 to search for a song and 0 to exit : "))
#OUTPUT-
#THANKYOU