-
-
Save canwe/e581181364db932a792ef01c3eb2d8be to your computer and use it in GitHub Desktop.
Python Permutation Generator : A generator that outputs all permutations of a sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def perm(xs) : | |
if xs == [] : | |
yield [] | |
for x in xs : | |
ys = [y for y in xs if not y==x] | |
for p in perm(ys) : | |
yield ([x] + p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment