Question: Using python3 to solve the problem 2. Bullding a Basic Playllst (12 polnts) Complete the buildPlayList ( function, which takes three arguments, in the following

 Using python3 to solve the problem 2. Bullding a Basic Playllst(12 polnts) Complete the buildPlayList ( function, which takes three arguments, in

Using python3 to solve the problem

2. Bullding a Basic Playllst (12 polnts) Complete the buildPlayList ( function, which takes three arguments, in the following order: (a) a dictionary of songs grouped by musical genre (like the one produced by the buildlibrary ) function from the previous step) (b) a list of strings representing one or more musical genres (c) an integer n representing the total number of songs to select for the resulting playlist This function returns a list of exactly n 2-element tuples (each tuple consists of a song title, followed by the artist name), randomly drawn from the genres specified above (and ONLY those genres). For example, if the second argument was the three-element list ["hip-hop", "classical", "metal'"], the new list should only contain songs from those three genresi.e., the result should not contain any songs that belong to a different genre like "country" or "reggae") If one or more of the requested genres do not exist in the library, your function should ignore that genre (for example, if the library had no "classical" songs in the example above, then the function should only consider songs from the "hip-hop" and "metal" genres). If the library does not contain ANY of the requested genres, then the function should return an empty list. If n is greater than the total number of songs that are available in all of the requested (and available) genres combined, the function should return a list with all of the songs in those genres combined, in any order. For example, if the user requests a 20-song playlist drawn from four genres that have 2, 5 4, and 6 songs respectively, the function should simply return a list with a 17 available songs Start by constructing a list of potential songs from each of the specified genres. Then use a function like random. sample (from the random modulesee the slides for an example of how to use this function) to construct your playlist. def buildPlayList (library, genres, length): # ADD YOUR CODE HERE return [] # CHANGE OR REPLACE THIS LINE

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!