Python Forum

Full Version: Creating permutations of N size with no same elements next to one another (recursion)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!