擅长:python、mysql、java
<p><a href="https://stackoverflow.com/users/43089/triptych">Triptych</a>启发了这个更一般的解决方案:</p>
<pre><code>def slicen(s, n, truncate=False):
assert n > 0
while len(s) >= n:
yield s[:n]
s = s[n:]
if len(s) and not truncate:
yield s
for op, code in slicen("+c-R+D-e", 2):
print op,code
</code></pre>