PythiloLesson 8 of 32 · progress kept in this browser

List every subset with include or skip

Every item faces one decision: in the subset or out. Two choices for each of n items give 2 ** n subsets. Recursion makes the decision for the first item and lets a smaller call handle the rest.

items = ["a", "b"]
# skip a: [], [b]   take a: [a], [a, b]
Your task

Write subsets(items) returning all 2 ** n subsets as lists, skip branch first, preserving item order inside each subset.