Recursion & Nested Playlists
In short: a recursive function solves a problem by calling itself on a smaller version of the same problem. Every recursive function needs a base case (an input small enough to answer directly, no further call) and a recursive case (do a little work, then call itself on something closer to the base case). Each call gets its own private frame on the call stack — frames pile up on the way down and come off, in reverse order, on the way up. Skip the base case and nothing ever stops the calls.

Flatten a nested playlist
Tunebox lets people put playlists inside playlists: "Road Trip" holds "Morning" and "Night", and "Night" holds "Late". One loop handles one level of nesting; two nested loops handle two. Recursion handles any depth, because it hands every sub-playlist to itself:
The mistake people really make: leaving the base case out, or writing it so the recursive call never gets closer to it. Then nothing ever stops:
def tracks_left(n):
return 1 + tracks_left(n - 1)
print(tracks_left(3))Flattening is the same shape, collecting titles instead of counting down. This version is one word away from right — a second real mistake:
This should print one flat list of four titles. It prints the sub-playlist as a list nested inside the result.