Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def permutations(L):
- if len(L) < 2: yield L
- else:
- for item in L:
- rest = L[:]; rest.remove(item)
- for permutation in permutations(rest):
- yield [item] + permutation
- def permutations(L):
- if len(L) < 2: yield L
- else:
- for item in L:
- i = L.index(item); rest = L[:i]+L[i+1:]
- for permutation in permutations(rest):
- yield [item] + permutation
- def permutations(L):
- if len(L) < 2: yield L
- else:
- for i in range(len(L)):
- for permutation in permutations(L[:i]+L[i+1:]):
- yield [L[i]] + permutation
- def permutations(L):
- if len(L) < 2: return [L]
- else: return ([L[i]]+permutation for i in range(len(L)) for permutation in permutations(L[:i]+L[i+1:]))
- def permutations(L):
- if len(L) < 2: yield L
- else:
- for permutation in permutations(L[:-1]):
- for i in range(len(L)):
- yield permutation[:i]+[L[-1]]+permutation[i:]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement