Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7017

Re: Lambda question

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '(except': 0.05; 'python': 0.08; 'recipe': 0.09; 'pm,': 0.10; 'this:': 0.10; 'def': 0.12; 'wrote:': 0.14; 'angelico': 0.16; 'docs,': 0.16; 'n):': 0.16; 'cc:addr:python-list': 0.17; 'cheers,': 0.19; 'header:In-Reply- To:1': 0.21; 'cc:2**0': 0.22; 'subject:question': 0.23; 'cc:no real name:2**0': 0.23; 'division': 0.23; 'least,': 0.23; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; "doesn't": 0.25; 'function': 0.25; 'received:209.85.161': 0.26; "i'm": 0.27; 'message- id:@mail.gmail.com': 0.28; 'sat,': 0.29; 'cc:addr:python.org': 0.30; 'array': 0.30; 'strings.': 0.30; 'seem': 0.32; "can't": 0.32; "skip:' 10": 0.32; 'someone': 0.33; 'chris': 0.34; 'else': 0.35; 'using': 0.35; 'received:google.com': 0.37; 'received:209.85': 0.37; 'case': 0.37; 'could': 0.38; 'anything': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'received:209': 0.39; 'allows': 0.40; 'simply': 0.60; 'special': 0.66; '12:09': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=l5H5/wLfQ9OohDfi3LQxHsL9LFLRPTkmVKcdoBiJzxw=; b=d1w5QCqmNExZDljOPhmN6GjTAljeyxrbvBXb7SP8+SXxz8vncw+RWXcC66L/ZB78ja HB4DAwmCUrcWDdDUgVKs3UvFZF/KKij3Jk6iv4+pCPMtIFvS/U+wx7jtmw8xyfhoc+vF +RW/UH1AydnVO5Aak4RBDejmcI9/3WlHlaNk8=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=KJuFv7qKYgANhvyuAjuJFEkDjR5Zwaq28TYXWo0Avt+kbQsVRfob8+OW/zA96QiXGh 6VG+U9c4B3BErDLpZItXr4EtlLiNyTXGsfmH6avSpGgFWEXPLP7HSHQ/rLvCGnY7goE9 FK5MEVwFKofSjGAwrw6ZXdTzeOpnlPtbV+sMM=
MIME-Version 1.0
In-Reply-To <BANLkTi==zFAgdPHk0TjyMESRcL=F1ZhpkA@mail.gmail.com>
References <20110604174624.V8FO6.213264.root@cdptpa-web07-z02> <BANLkTi==zFAgdPHk0TjyMESRcL=F1ZhpkA@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Sat, 4 Jun 2011 13:28:47 -0600
Subject Re: Lambda question
To Chris Angelico <rosuav@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2456.1307215764.9059.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 82.94.164.166
X-Trace 1307215765 news.xs4all.nl 49176 [::ffff:82.94.164.166]:50220
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7017

Show key headers only | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Lambda question Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-04 13:28 -0600

csiph-web