I want to get all the possible permutations of two different elements grouped by four without repeating the output but repeating elements (obviously you need to repeat elements to make combinations of 4 with only 2 elements).
So, some things I've tried:
sorted(list(map(lambda x: "".join(x), list(permutations('AB', 4)))))
returns an empty list. So I tried this instead:
sorted(list(map(lambda x: "".join(x), list(permutations('AABB', 4)))))
And it is closed to the output I expect, but full of redundant items, just a few of them:
['AABB','AABB','AABB','AABB','ABAB','ABAB','ABAB',...
What I expected to get is actually:
['AABB','ABAB','ABBA','BAAB','BABA','BBAA']
I tried also combinations() and product() instead of permutations() without success, but maybe my arguments weren't fit to the problem.
Any ideas?
Thanks a lot in advance!
PS. As pointed out by Antoine, there's a workaround using a set instead of a list, like:
sorted(list(map(lambda x: "".join(x), set(permutations('AABB', 4)))))
That gives the expected output, still it is generating all the repetitions anyway but just happen to be filtered out because sets cannot have repeated element, so it's probably not the most efficient way to do it.