Created
March 25, 2012 14:02
-
-
Save vivekn/2194844 to your computer and use it in GitHub Desktop.
CodeDef - Permutations
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 permg(seq): | |
""" | |
Returns a generator of permutations for a sequence. | |
""" | |
if len(seq) <= 1: | |
yield seq | |
else: | |
for perm in permg(seq[1:]): | |
for i in range(len(seq)): | |
yield perm[:i] + seq[0:1] + perm[i:] | |
result = sorted(permg('0123456789')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment