title: Generating all possible k-mers (string combinations) from a given list
body: <p>I have a string <code>S</code> that is composed of 20 characters: </p>
  
  
  
  <pre class="lang-python prettyprint-override"><code>S='ARNDCEQGHILKMFPSTWYV'
  </code></pre>
  
  <p>I need to generate all possible k-mer combinations from a given input k.</p>
  
  <p>When <code>k == 3</code>, then there are 8000 combinations (<code>20*20*20</code>) and the output list looks like this:</p>
  
  <pre class="lang-python prettyprint-override"><code>output = ['AAA', 'AAR', ..., 'AVV', ..., 'VVV'] #len(output)=8000
  </code></pre>
  
  <p>When <code>k == 2</code>, then there are 400 combinations (<code>20*20</code>) and the output list looks like this: </p>
  
  <pre class="lang-python prettyprint-override"><code>output = ['AA', 'AR', 'AN', ..., 'VV'] #len(output)=400
  </code></pre>
  
  <p>When <code>k == 1</code>, then there are only 20 combinations:</p>
  
  <pre class="lang-python prettyprint-override"><code>output =['A', 'R', 'N', ..., 'Y', 'V'] #len(output)=20
  </code></pre>
  
  <p>I know how to do this if the number <code>k</code> is fixed, like if <code>k == 3</code>, then I can do this: </p>
  
  <pre class="lang-python prettyprint-override"><code>for a in S:
     for b in S:
        for c in S:
           output.append(a+b+c)
  #then len(output)=8000
  </code></pre>
  
  <p>But the number <code>k</code> is chosen randomly.
  I tried to use permutations, but it does not given me strings with repeated letters like <code>'AAA'</code>, but maybe it can and I'm just doing it wrong. </p>