On Sat, Jun 4, 2011 at 12:09 PM, Chris Angelico <ros...@gmail.com> wrote: > Python doesn't seem to have an inbuilt function to divide strings in > this way. At least, I can't find it (except the special case where n > is 1, which is simply 'list(string)'). Pike allows you to use the > division operator: "Hello, world!"/3 is an array of 3-character > strings. If there's anything in Python to do the same, I'm sure > someone else will point it out.
Not strictly built-in, but using the "grouper" recipe from the itertools docs, one could do this: def strsection(x, n): return map(''.join, grouper(n, x, '')) Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list