How to generate permutations without generating repeating results but with a fixed amount of characters Python
Question: I am trying to figure out a way to generate all permutations possible of a
string that has a couple repeating characters but without generating repeated
tuples.

Right now I am using `itertools.permutations()`. It works but I need to remove
repetition and I **cannot** use `set()` to remove the repetition.

What kind of results am I expecting? Well, for example, I want to get all the
combinations for `DDRR`, the thing with `itertools.permutations()` is that I
would get `DDRR` about four times, given that `itertools` sees the `D`s as if
they were different, same with `R`s.

With `list(itertools.permutations('DDRR'))` I get:

    
    
    [('D', 'D', 'R', 'R'), ('D', 'D', 'R', 'R'), ('D', 'R', 'D', 'R'), ('D', 'R', 'R', 'D'), ('D', 'R', 'D', 'R'), ('D', 'R', 'R', 'D'), ('D', 'D', 'R', 'R'), ('D', 'D', 'R', 'R'), ('D', 'R', 'D', 'R'), ('D', 'R', 'R', 'D'), ('D', 'R', 'D', 'R'), ('D', 'R', 'R', 'D'), ('R', 'D', 'D', 'R'), ('R', 'D', 'R', 'D'), ('R', 'D', 'D', 'R'), ('R', 'D', 'R', 'D'), ('R', 'R', 'D', 'D'), ('R', 'R', 'D', 'D'), ('R', 'D', 'D', 'R'), ('R', 'D', 'R', 'D'), ('R', 'D', 'D', 'R'), ('R', 'D', 'R', 'D'), ('R', 'R', 'D', 'D'), ('R', 'R', 'D', 'D')]
    

The ideal result I want is:

    
    
    [('D', 'R', 'R', 'D'), ('R', 'D', 'R', 'D'), ('R', 'R', 'D', 'D'), ('D', 'R', 'D', 'R'), ('D', 'D', 'R', 'R'), ('R', 'D', 'D', 'R')]
    


Answer: Make use of a set which only generates unique tuples of permutations like so:

    
    
    >>> from itertools import permutations
    >>> perms = set(permutations('DDRR'))
    >>> perms
    set([('R', 'R', 'D', 'D'), ('D', 'R', 'R', 'D'), ('R', 'D', 'R', 'D'), ('D', 'D', 'R', 'R'), ('D', 'R', 'D', 'R'), ('R', 'D', 'D', 'R')])
    

You can easily convert it back to a list if needed by just doing
`list(perms)`.

