Skip to content

Instantly share code, notes, and snippets.

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