fork download
  1. def comb(L):
  2. if len(L) <= 1:
  3. return [L]
  4. c = []
  5. for i in range(len(L)):
  6. for k in comb(L[:i] + L[i + 1:]):
  7. c.append([L[i]] + k)
  8. return c
  9.  
  10. print(comb([1, 2, 3]))
  11.  
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]]