Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write the data in variable artist_songs into a csv file, 'songs.txt', where the first column is singer name and second column is a song name.
Write the data in variable artist_songs into a csv file, 'songs.txt', where the first column is singer name and second column is a song name. Each line should have a singer and a song name. Use "Name" and "Song" as headers. Do not include double quotation marks (") in your CSV but you should include apostrophes where necessary (for example, for the song "We Don't Talk Anymore").
I did this so far but I am confused with what to do with the code.
Problem 10 Write the data in variable artist_songs into a csv file, 'songs.txt', where the first column singer name and second column is a song name. Each line should have singer and a song name. Use "Name" and "Song " as headers. Do not include double quotation marks (") in your CSV but you should include apostrophes where necessary (for example, for the song "We Don't Talk Anymore"). In [ ]: artist_songs = { Taylor Swift': [ 'Love Story', 'You need to calm Down'], Charlie Puth': [ 'Attention', "We Don't Talk Anymore", Change'] In [*]: # write your code for problem 10 here artist_songs = open('songs.txt', 'W') artist_songs.write("Name, Song' ") for song in artist_songs. items(): for x in song: x.write('{}, {} '.format(artists,x)) artist_songs.close() 'r') a = open('songs.txt', b = a.read() print(b)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started