Skip to content

Instantly share code, notes, and snippets.

@cammckinnon
Forked from anonymous/gist:4304103
Created December 16, 2012 07:54
Show Gist options
  • Save cammckinnon/4304128 to your computer and use it in GitHub Desktop.
Save cammckinnon/4304128 to your computer and use it in GitHub Desktop.
import re
from itertools import *
string = raw_input()
parts = re.split('([^a-zA-Z]+)', string)
alpha_parts = [part for part in parts if re.match("[a-zA-Z]+",part)]
perms = permutations(apply(chain,alpha_parts))
for result in set(perms):
printme = ""
index = 0
for char in string:
if re.match("[a-zA-Z]",char):
printme += result[index]
index += 1
else:
printme += char
print printme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment