Advertisement
Guest User

get permutations

a guest
Nov 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1.  
  2. def get_permutations(sequence):
  3.     list = []
  4.     if len(sequence) == 1:
  5.         list.append(sequence)
  6.     else:
  7.         list = []
  8.         for i in range(len(sequence)):
  9.             permuteList = get_permutations(sequence[0:i] + sequence[i+ 1:])
  10.             for item in permuteList:
  11.                 list.append(sequence[i] + item)
  12.     return list
  13.  
  14. def remove_duplicates(list):
  15.     list2 = []
  16.     for i in list:
  17.         if i not in list2:
  18.             list2.append(i)
  19.     return list2
  20.  
  21. yyggg = len(remove_duplicates(get_permutations("yyggg")))
  22. ryggg = len(remove_duplicates(get_permutations("ryggg")))
  23. ryygg = len(remove_duplicates(get_permutations("ryygg")))
  24. print("yggg: " , yyggg)
  25. print("ryggg: ", ryggg)
  26. print("ryygg: " , ryygg)
  27. print("total: " , ryggg + ryygg + yyggg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement