Skip to content

Instantly share code, notes, and snippets.

@trendsetter37
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trendsetter37/22b24ebe646983ad4cc3 to your computer and use it in GitHub Desktop.
Save trendsetter37/22b24ebe646983ad4cc3 to your computer and use it in GitHub Desktop.
String permutations Hard challenge on CodeEval
import itertools
import sys
def sort_perm(perm_list):
''' This will sort the list of permutations in
your into a list of tuples/list'''
teh_list = sorted(perm_list)
for item in teh_list:
if (item == teh_list[len(teh_list) - 1]):
for letter in item:
if (letter == item[len(item) - 1]):
print("{0}".format(letter))
else:
print("{0}".format(letter), end="")
else:
for letter in item:
print("{0}".format(letter), end="")
print(",", end="")
def create_permutations(string):
result = itertools.permutations(string, len(string))
return result
with open(sys.argv[1], "r") as f:
for line in f:
perm_list = []
for perm in create_permutations(line.strip('\n')):
perm_list.append(perm)
sort_perm(perm_list)
@trendsetter37
Copy link
Author

Could make this more efficient. Will get on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment