Last active
August 29, 2015 14:07
-
-
Save trendsetter37/22b24ebe646983ad4cc3 to your computer and use it in GitHub Desktop.
String permutations Hard challenge on CodeEval
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could make this more efficient. Will get on that.