Earlier today I needed to iterate over a string 2 characters at a time for parsing a string formatted like \"+c-R+D-E\" (there are a few extra letters).
\"+c-R+D-E\"
I ran into a similar problem. Ended doing something like this:
ops = iter("+c-R+D-e") for op in ops code = ops.next() print op, code
I felt it was the most readable.