title: Python itertools permutations without repetitions
body: <p>I have a string show the step going in m x n grid like this problem:
  <a href="https://leetcode.com/problems/unique-paths/" rel="nofollow noreferrer">https://leetcode.com/problems/unique-paths/</a></p>
  
  <pre><code>step = 'DDRR'
  </code></pre>
  
  <p>D mean go Down and R mean go to Right
  I want to show permutations without replacement, and i found the itertools built-in on Python.But it's say:</p>
  
  <blockquote>
    <p>Elements are treated as unique based on their position, not on their value. So if the input elements are unique, there will be no repeat values.   </p>
  </blockquote>
  
  <p>So that when I using itertools.permutation(step,4), it's contain many replications.</p>
  
  <pre><code>&gt;&gt;&gt; itertools.permutations(step,4)
  ('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')
  </code></pre>
  
  <p>I want something like:</p>
  
  <pre><code>('R', 'D', 'R', 'D')
  ('R', 'D', 'D', 'R')
  ('D', 'R', 'R', 'D')
  ('D', 'D', 'R', 'R')
  ('D', 'R', 'D', 'R')
  ('R', 'R', 'D', 'D')
  </code></pre>
  
  <p>I found some answer using <strong>set(itertools.permutations(step,4))</strong>, but because apply set() method, the itertools.permutation() method still calculate all possibilities. Is there anyway to avoid it, or <strong>is there any built-in function can do permutation without repetitions in Python</strong>?</p>