Skip to content

Instantly share code, notes, and snippets.

@canwe
Forked from interstar/permgen.py
Created November 7, 2020 15:05
Show Gist options
  • Save canwe/e581181364db932a792ef01c3eb2d8be to your computer and use it in GitHub Desktop.
Save canwe/e581181364db932a792ef01c3eb2d8be to your computer and use it in GitHub Desktop.
Python Permutation Generator : A generator that outputs all permutations of a sequence
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