Created
April 14, 2015 05:59
-
-
Save larainema/6dabd460de0102c09531 to your computer and use it in GitHub Desktop.
get all possible combinations of characters given a string
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 allperm(inputstr): | |
for i in range(len(inputstr)): | |
yield(inputstr[i]) | |
for s in allperm(inputstr[:i] + inputstr[i+1:]): | |
yield(inputstr[i] + s) | |
inputstr = "abc" | |
for n in allperm(inputstr): | |
print n | |
import sys | |
from itertools import permutations | |
inputstr = sys.argv[1].upper() | |
print inputstr | |
perms = (p for p in permutations(inputstr)) | |
for p in perms: | |
print ''.join(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment