fork download
  1. def permutate_pf(v, res, l=0):
  2. if l==len(v)-1:
  3. res.append(v)
  4. return
  5.  
  6. for i in range(l, len(v)):
  7. t = []
  8. t.append(v[i])
  9. for j in range(len(v)):
  10. if(j!=i):
  11. t.append(v[j])
  12. permutate_pf(t, res, l+1)
  13.  
  14. res = []
  15.  
  16. permutate_pf([1,2,3], res)
  17.  
  18. print(res)
  19.  
Success #stdin #stdout 0.04s 63628KB
stdin
Standard input is empty
stdout
[[2, 1, 3], [3, 1, 2], [1, 2, 3], [3, 2, 1], [1, 3, 2], [2, 3, 1]]