Dec-18-2021, 06:06 PM
Hello everyone! I am studying python from a Romanian book, and I have been trying some exercises on recursion.
I am quite struggling with this one: I am supposed to find all permutations of size K with recursion, without there being identical elements next to one another.
So, given a list [a,b,c,d] and K=3:
(a,b,c)
(a,b,d)
would be valid permutations.
The exercise asks precisely to append the permutations to a list (so generators are out of the question) and return it.
Any help would be appreciated.
Thanks in advance!
I am quite struggling with this one: I am supposed to find all permutations of size K with recursion, without there being identical elements next to one another.
So, given a list [a,b,c,d] and K=3:
(a,b,c)
(a,b,d)
would be valid permutations.
The exercise asks precisely to append the permutations to a list (so generators are out of the question) and return it.
Any help would be appreciated.
Thanks in advance!