title: Python: how to count overlapping occurrences of a substring
body: <p>I wanted to count the number of times that a string like 'aa' appears in 'aaa' (or 'aaaa'). </p>
  
  <p>The most obvious code gives the wrong (or at least, not the intuitive) answer:</p>
  
  <pre><code>'aaa'.count('aa')
  1 # should be 2
  'aaaa'.count('aa')
  2 # should be 3
  </code></pre>
  
  <p>Does anyone have a simple way to fix this?</p>