title: Iterate over a string 2 (or n) characters at a time in Python
body: <p>Earlier today I needed to iterate over a string 2 characters at a time for parsing a string formatted like <code>"+c-R+D-E"</code> (there are a few extra letters).</p>
  
  <p>I ended up with this, which works, but it looks ugly.  I ended up commenting what it was doing because it felt non-obvious.  It almost seems pythonic, but not quite.</p>
  
  <pre><code># Might not be exact, but you get the idea, use the step
  # parameter of range() and slicing to grab 2 chars at a time
  s = "+c-R+D-e"
  for op, code in (s[i:i+2] for i in range(0, len(s), 2)):
    print op, code
  </code></pre>
  
  <p>Are there some better/cleaner ways to do this?</p>