Created
March 2, 2011 13:31
-
-
Save ideamonk/850932 to your computer and use it in GitHub Desktop.
such a fucked up piece of fuck
This file contains hidden or 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
def findAllPerm(string): | |
def findAll(slist): | |
if len(slist)==1: | |
return slist | |
else: | |
biglist = [] | |
for i in xrange(len(slist)): | |
temp = [slist[i]] | |
temp.extend(findAll(slist[:i]+slist[i+1:])) | |
if len(temp)==2 and type(temp[0])==type(''): | |
temp = ''.join(temp) | |
biglist.append(temp) | |
return biglist | |
def flattenAndAppend(listy_list, prefix): | |
if len(listy_list)==3 and type(listy_list[1])==type(''): | |
junk = [prefix + listy_list[0] + x for x in listy_list[1:]] | |
for j in junk: | |
try: | |
goldRush[j] | |
except: | |
goldRush[j]=1 | |
muchBiggerList.append(j) | |
elif len(listy_list)>3 and type(listy_list[1])==type([]): | |
prefix += listy_list[0] | |
for x in listy_list[1:]: | |
flattenAndAppend(x, prefix) | |
goldRush = {} | |
muchBiggerList = [] | |
junky_shit = findAll([x for x in string]) | |
if len(junky_shit)<=2: | |
return junky_shit | |
else: | |
for j in junky_shit: | |
flattenAndAppend(j,'') | |
return muchBiggerList | |
print findAllPerm("aaab") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment