Further to this problem: Print n-length combinations from char list using recursion
Now I have to implement the same algorithm with some another twist: without repetitions of some char.
Implement a function in Python which recieves as parameters list of characters and an integer n. The function has to print all the possible combinations in the length of n, where every character can be shown only one time.
So, as I am a beginner and bad in recursion, I don't succeed to think of an elegant solution to solve that.
I have thought to use the same code from the previous problem:
def print_sequences(char_list, n, _accum=[]):
if len(_accum) == n:
print(_accum)
else:
for c in char_list:
print_sequences(char_list, n, _accum+[c])
And simply build a new function (return_without_repetition) that takes a list and goes over it, builds a new list without repetitions. Such that when I print the list I use the function:
if len(_accum) == n:
print(return_without_repetition(_accum))
But it's very not effective and not elegant.
Maybe there is another way to solve it by defining new lists in the body of the recursion but I got lost concerning the scoping and the suitable places to define the lists...