So been struggling with this one, I'm close and have finally found a way to somewhat desired output now repeats in generated list.
input['a','r','t']
def permutations(string_list):
if len(string_list) <= 1:
return [string_list]
perm_list = []
for letter_index in range(len(string_list)):
perms_1 = string_list[letter_index]
rest = string_list[:letter_index] + string_list[letter_index + 1:]
for perms_2 in permutations(rest):
perm_list.append([perms_1] + perms_2)
return perm_list
output
[[['a', 'r', 't'], ['a', 't', 'r'], ['r', 'a', 't'], ['r', 't', 'a'],
['t', 'a', 'r'], ['t', 'r', 'a']], [['a', 'r', 't'], ['a', 't', 'r'],
['r', 'a', 't'],
.........repeats.......repeats..
..for quite sometime but not infinite....]]]
DESIRED output
[['a', 'r', 't'], ['a', 't', 'r'], ['r', 'a', 't'], ['r', 't', 'a'],
['t', 'a', 'r'], ['t', 'r', 'a']]
so it's permutation but what is tripping me up is having to use the list of strings and outputting a list of lists of strings. I have redone this multiple time and have the basis of recursive permutations down if I was just using a string 'art' as input or having a list output ['art','atr','rat',ect..] just not sure where I am going wrong. No import of itertools allowed and really wish I didn't need for loops but using comprehension recursion call gives me same results...any help or pointers appreciated. Not looking for just a redo I want to understand....