title: Check that python list follows a specific repeating pattern
body: <p>I have a python list which contains only two symbols, let us say they are <code>a</code> and <code>b</code> and the list looks like so:</p>
  
  <pre><code>l = ['a','b','a','b','a','b','a','b','a','b','a','b','a','b','a','b']
  </code></pre>
  
  <p>Now in my application, I have thousands of these lists, and they vary in length (typically a few hundred long). But what they all have in common is that they have the repeating pattern <code>(a,b)</code>. This list, for example, is broken:</p>
  
  <pre><code>l_broken = ['a','b','b','a','a','b','a','b','a','a','a','b','a','b','b','a']
  </code></pre>
  
  <p>Anything which deviates from the <code>a,b</code> repeating pattern in <code>l</code> must be considered broken. Even if the list is not of even length, then it is broken. So this must be a very strict test. But essentially if the list <code>l</code> is of length <code>N</code> then it means that <code>(a,b)</code> has to repeat itself <code>N/2</code> times. The symbols <code>a</code> and <code>b</code> are the only things that will ever appear in these lists, so checking for that is not required since it is inconceivable in this application, for anything else to be seen.</p>
  
  <p>I should say that they all <em>should</em> have the <em>first</em> pattern. I am looking for an efficient way, a test, that can determine that each list does, in fact, have this repeating pattern. And if not throw an error or something e.g.</p>
  
  <pre><code>assert my_fancy_test(l), 'the list does not follow the correct pattern'
  </code></pre>
  
  <p>I think I am looking for sub-sequence matching, but my google searches are coming up short. </p>
  
  <h2>EDIT:</h2>
  
  <p>Thank you all for your excellent solutions. I had no idea you could do even half of these. Great stuff. I added a short performance overview at the end for you to peruse.</p>