fork download
def comb(L):
    if len(L) <= 1:
        return [L]
    c = []
    for i in range(len(L)):
        for k in comb(L[:i] + L[i + 1:]):
            c.append([L[i]] + k)
    return c

print(comb([1, 2, 3]))
Success #stdin #stdout 0.03s 9596KB
stdin
Standard input is empty
stdout
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]