Advertisement
misingnoglic

Untitled

Jan 17th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. def permutations(L):
  2. if len(L) < 2: yield L
  3. else:
  4. for item in L:
  5. rest = L[:]; rest.remove(item)
  6. for permutation in permutations(rest):
  7. yield [item] + permutation
  8.  
  9. def permutations(L):
  10. if len(L) < 2: yield L
  11. else:
  12. for item in L:
  13. i = L.index(item); rest = L[:i]+L[i+1:]
  14. for permutation in permutations(rest):
  15. yield [item] + permutation
  16.  
  17. def permutations(L):
  18. if len(L) < 2: yield L
  19. else:
  20. for i in range(len(L)):
  21. for permutation in permutations(L[:i]+L[i+1:]):
  22. yield [L[i]] + permutation
  23.  
  24. def permutations(L):
  25. if len(L) < 2: return [L]
  26. else: return ([L[i]]+permutation for i in range(len(L)) for permutation in permutations(L[:i]+L[i+1:]))
  27.  
  28. def permutations(L):
  29. if len(L) < 2: yield L
  30. else:
  31. for permutation in permutations(L[:-1]):
  32. for i in range(len(L)):
  33. yield permutation[:i]+[L[-1]]+permutation[i:]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement