Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7017 > unrolled thread
| Started by | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| First post | 2011-06-04 13:28 -0600 |
| Last post | 2011-06-04 13:28 -0600 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Lambda question Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-04 13:28 -0600
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2011-06-04 13:28 -0600 |
| Subject | Re: Lambda question |
| Message-ID | <mailman.2456.1307215764.9059.python-list@python.org> |
On Sat, Jun 4, 2011 at 12:09 PM, Chris Angelico <rosuav@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
Back to top | Article view | comp.lang.python
csiph-web