title: How do I get possible combinations of a list within a specific range in Python?
body: <p>Let's say I have this list:</p>
  
  <pre><code>letters = list('ABCDEFGHIJKLMNOPQ')
  </code></pre>
  
  <p>How can I get possible combinations of this list within a range of only 4 characters?</p>
  
  <p>So my result set would be, for example:</p>
  
  <ul>
  <li>ABC</li>
  <li>NIJK</li>
  <li>C</li>
  <li>FK</li>
  <li>QACD</li>
  <li>....</li>
  </ul>
  
  <p>I tried it like this, but this does not seem to work:</p>
  
  <pre><code>for L in range(0, 4):
      for subset in itertools.permutations(letters, L):
          word = ''.join(subset)
          print(word)
  </code></pre>