Round-Robin Playlist

Python for AIHard+10 XP+10

Round-Robin Playlist

A Playlist plays songs in a loop: after a song plays, it goes to the back of the queue.

Part 1: Playlist()

A new playlist has an empty list in songs. Add three methods:

  • add(song) puts the song at the end. If it's already in the playlist, do nothing.
  • remove(song) takes the song out. If it isn't there, do nothing (no error).
  • play_next() returns the first song and moves it to the end of the list. If the playlist is empty, return None.

Part 2: listen(songs, removed, plays)

Make a playlist. Add every song in songs, in order. Then remove every song in removed. Then call play_next() exactly plays times. Return the list of everything play_next() gave back.

Examples

songs = ['Up', 'Down']
removed = []
plays = 3
returns ['Up', 'Down', 'Up']
songs = ['Up', 'Down']
removed = ['Up']
plays = 2
returns ['Down', 'Down']
songs = ["A", "B", "C"]
removed = []
plays = 4
returns ['A', 'B', 'C', 'A']
songs = ["A", "B", "A", "C"]
removed = ["B"]
plays = 3
returns ['A', 'C', 'A']

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run