Example: <pre>
>>> list(splitIterator("102030405", 2))
['10', '20', '30', '40', '5']
</pre>
1 2 3 4 | def splitIterator(text, size):
assert size > 0, "size should be > 0"
for start in xrange(0, len(text), size):
yield text[start:start + size]
|
Tags: shortcuts
another option... another implementation:
</pre>
Not sure what happened there... ASPN seems to have mangled my post...
list comprehension (abstraction).