Skip to content

Instantly share code, notes, and snippets.

@devils-ey3
Created September 21, 2016 11:02
Show Gist options
  • Save devils-ey3/cbc34a8a9e69e873ee69edd8c58332ba to your computer and use it in GitHub Desktop.
Save devils-ey3/cbc34a8a9e69e873ee69edd8c58332ba to your computer and use it in GitHub Desktop.
Parmutation algorithm by python 3x
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