Build permutations by fixing one item
A recursive function solves a problem by trusting a smaller copy of itself. To order n items, choose which item goes first, then ask for every ordering of the remaining items.
def count(n):
return 1 if n <= 1 else n * count(n - 1)
print(count(4)) # 24 orderingsThink before coding
The base case is an empty list, which has exactly one ordering: the empty one. Each level loops over the items, removes one and prefixes it to every smaller ordering. Removing by position keeps repeated values correct. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write permutations(items) returning every ordering of items as a list of lists, in the order produced by choosing positions left to right.
The explanation opens here once every check passes.