title: Itertools stop characters repeating in a row
body: <p>I wrote the following code to make all strings of 20 characters long with combinations of A, T, G and C. </p>
  
  <p>However, I would like to avoid more than 3 of the same characters in a row, so I added an if function to check for this. The trouble is, this is after the itertools code, so it's a bit slow. I wonder whether there is a way to use itertools to produce this result without having to run itertools and then an if function?</p>
  
  <pre><code>import sys
  import itertools
  import re
  
  x = ["A","T","G","C"]
  for i in itertools.product(x, repeat=20):
          i = "".join(i)
          if re.search(r"(\w)\1\1",i):
                  continue
          else:
                  sys.stdout.write(i)
  </code></pre>