Question: Using python3 to solve the problem Creating Custom Playlists Suppose that you have a side business working as a DJ for parties and other events.


Using python3 to solve the problem
Creating Custom Playlists Suppose that you have a side business working as a DJ for parties and other events. Each event runs for a different length of time and has a different clientele, so you need a way to quickly generate a customized playlist of songs from your music library. In this assignment, you will write a program that will handle this task for you (or let you know that the task is impossible using the current music library and/or with the specified set of constraints). 1. Constructing a LIbrary (8 polnts) First, we need to assemble our library of songs. Each song has several attributes associated with it: ethe song title e the artist who performed the song the song's genre (e.g., "rock") e the song's length (measured in seconds) We will collect this information from a (plain text) data file and store it in a dictionary. Each key in the dictionary corresponds to a unique genre; its value will be a list of songs (from the data file that belong to that genre. Each song is represented by a list (or tuple wih exactly three elements, in the following order: title (a string), artist (a string), and length in seconds (an integer). For example: "rock" :("We' re Not Gonna Take It", "Twisted Sister", 217), "Born To be Wild", "Steppenwolf", 211), "Pinball Wizard", "The Who", 182) denotes that our library contains three songs that belong to the "rock" genre Start by completing the buildlibrary) function. This function takes a single string argument, repre- senting the name of a data file. The function returns a dictionary in the format above that has been created using the contents of the data file Each line of the data file contains information about a single song, in the following order (fields are separated by commas; assume that there are no leading/trailing spaces between fields): song genre, song title, artist, song length (in MM:SS format) For example, "jazz,Sputnik,Conrad Boqvist,5:05" describes a jazz song ("Sputnik", by Conrad Boqvist, whose length is 305 seconds (5 minutes, 5 seconds). HInt: To convert the time string into seconds, split it based on the colon(") character. Convert each piece to an integer, and perform the appropriate arithmetic Your general solution strategy should be as follows: Set 1ibrary to an empty dictionary For each 1ine in the data file: Split th ine based on commas Convert the "time" element into an integer number of seconds Create a new 1ist or tuple with the song title, artist, and length Add the new 1ist to your dictionary, using the genre as the key Return the dictionary def buildLibrary (filename # ADD YOUR CODE HERE return () # CHANGE OR REPLACE THIS LINE
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
