Skip to content

Instantly share code, notes, and snippets.

@larainema
Created April 14, 2015 05:59
Show Gist options
  • Save larainema/6dabd460de0102c09531 to your computer and use it in GitHub Desktop.
Save larainema/6dabd460de0102c09531 to your computer and use it in GitHub Desktop.
get all possible combinations of characters given a string
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