Created
September 21, 2016 11:02
-
-
Save devils-ey3/cbc34a8a9e69e873ee69edd8c58332ba to your computer and use it in GitHub Desktop.
Parmutation algorithm by python 3x
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
def parmutation(list): | |
if len(list)==0: | |
return [] | |
elif len(list)==1: | |
return [list] | |
else: | |
new_list = [] | |
print("New list --> ",new_list,"Len newlist --> ",len(new_list)) | |
print("Len before for loop -->",len(list)) | |
for i in range(len(list)): | |
print("Value of i is ",i) | |
x = [list[i]] | |
xs = list[:i] + list[i+1:] | |
print("x = ",x," Len ",len(x)," xs = ",xs," len ",len(xs)) | |
for p in parmutation(xs): | |
print("Value of p is ",p) | |
new_list.append(x+p) | |
print(" New list --> ",new_list) | |
return new_list | |
s = list("1234") | |
removeDupli = [] | |
for i in parmutation(s): | |
if i not in removeDupli: | |
removeDupli.append(i) | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment