Recursion · stretch
Every subset
Write subsets(items) returning a list of every subset of the list (each subset a list, items in their original order). [1, 2] gives [], [1], [2], [1, 2] in any order.
Every subset either leaves out the first item or includes it — and the rest is the same problem, one item shorter.
- right answers
- arguments left as they should be
- without combinations, itertools, product
Run adds print(subsets([1, 2, 3])) after your code, to try it.
Stuck on the idea rather than the code? The Recursion that halves, and recursion that branches lesson walks through it.