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


Groups > comp.lang.python > #108165

Re: Whittle it on down

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Stephen Hansen <me+python@ixokai.io>
Newsgroups comp.lang.python
Subject Re: Whittle it on down
Date Thu, 05 May 2016 00:34:29 -0700
Lines 49
Message-ID <mailman.401.1462433672.32212.python-list@python.org> (permalink)
References <ngejmj$gc4$1@dont-email.me> <572ae25f$0$2821$c3e8da3$76491128@news.astraweb.com> <1462430766.25079.598726825.1B90C7A1@webmail.messagingengine.com> <mailman.398.1462430769.32212.python-list@python.org> <572af09d$0$1508$c3e8da3$5496439d@news.astraweb.com> <1462433669.32454.598751585.63AF2D12@webmail.messagingengine.com>
Mime-Version 1.0
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de rlajCNNylCOZkMsSNhJu5Qi9flHVQkeLw224PDP67FRg==
Return-Path <me+python@ixokai.io>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'correct.': 0.07; 'logic': 0.09; 'received:internal': 0.09; 'splitting': 0.09; 'python': 0.10; 'wed,': 0.15; 'thu,': 0.15; '12:04': 0.16; '2016': 0.16; 'cryptic': 0.16; 'enough.': 0.16; 'meh.': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'recognizing': 0.16; 'rejects': 0.16; 'said.': 0.16; 'wrongly': 0.16; 'wrote:': 0.16; 'string': 0.17; 'instance,': 0.18; "shouldn't": 0.18; 'version.': 0.18; 'simpler': 0.22; 'stephen': 0.22; 'am,': 0.23; 'bit': 0.23; 'seems': 0.23; 'matching': 0.23; "python's": 0.23; "haven't": 0.24; 'header:In-Reply-To:1': 0.24; 'otherwise.': 0.27; 'function': 0.28; 'idea': 0.28; 'regular': 0.29; 'accepts': 0.29; 'faster,': 0.29; 'strings,': 0.29; "i'm": 0.30; 'call.': 0.30; 'version,': 0.30; 'extend': 0.31; 'probably': 0.31; 'language.': 0.32; 'problem': 0.33; "d'aprano": 0.33; 'steven': 0.33; "i'll": 0.33; 'definition': 0.34; 'exist': 0.35; 'important.': 0.35; "isn't": 0.35; 'problem.': 0.35; 'sometimes': 0.35; 'but': 0.36; 'smaller': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'really': 0.37; 'received:66': 0.38; 'sure': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'still': 0.40; 'easy': 0.60; 'care': 0.60; 'your': 0.60; 'skip:u 10': 0.61; 'header :Message-Id:1': 0.61; 'more': 0.63; 'thursday': 0.66; 'account': 0.66; 'situation': 0.67; 'customers': 0.70; '95%': 0.84; 'compact,': 0.84; 'distinguish': 0.84; 'greek': 0.84; 'nonsense.': 0.84; 'subject:down': 0.84; 'good,': 0.93
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d=ixokai.io; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=2ZNsZyaYRoTAAFJb2ILdN8N1hms=; b=Jykw7h yJJ0ou13BrLjDt8Cx/oL+QHCY0z/UZ/J0y1qlx3l6/CPZumQEgyfVqnSG+jptpEk MeKWSzg8ev0Iizu4rfVq3Fp2gKy+2BJNuYU/IU146XDm4hmjHYRU6kQpewT5cntZ +0cEi44vKZx2tmnpWHNxEC2z/fQlQcP62Gb9g=
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=2ZNsZyaYRoTAAFJ b2ILdN8N1hms=; b=XZhgpxajEXh10Ojg6gf8XUVr7et3h/TpzBJTwac5dOCqDK4 mUtchAZ0Zdylv1BUIqhkHiy6Jo2CjogPnWCwvkILippLieoBcWx5dbe+mEJKoNZO nqyBAhYgzz71iQ3jpVbm6u/hypTvfl7+ux5pAs/1zNBOzNxOjh2tkNnsFexw=
X-Sasl-Enc eT+7ALtDTXhfFhhvfoEQ4IjrlCTX62C9hAQGDGko0uuK 1462433669
X-Mailer MessagingEngine.com Webmail Interface - ajax-9f40a94e
In-Reply-To <572af09d$0$1508$c3e8da3$5496439d@news.astraweb.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <1462433669.32454.598751585.63AF2D12@webmail.messagingengine.com>
X-Mailman-Original-References <ngejmj$gc4$1@dont-email.me> <572ae25f$0$2821$c3e8da3$76491128@news.astraweb.com> <1462430766.25079.598726825.1B90C7A1@webmail.messagingengine.com> <mailman.398.1462430769.32212.python-list@python.org> <572af09d$0$1508$c3e8da3$5496439d@news.astraweb.com>
Xref csiph.com comp.lang.python:108165

Show key headers only | View raw


On Thu, May 5, 2016, at 12:04 AM, Steven D'Aprano wrote:
> On Thursday 05 May 2016 16:46, Stephen Hansen wrote:
> > > On Wed, May 4, 2016, at 11:04 PM, Steven D'Aprano wrote:
> >> Start by writing a function or a regex that will distinguish strings that
> >> match your conditions from those that don't. A regex might be faster, but
> >> here's a function version.
> >> ... snip ...
> > 
> > Yikes. I'm all for the idea that one shouldn't go to regex when Python's
> > powerful string type can answer the problem more clearly, but this seems
> > to go out of its way to do otherwise.
> > 
> > I don't even care about faster: Its overly complicated. Sometimes a
> > regular expression really is the clearest way to solve a problem.
> 
> You're probably right, but I find it easier to reason about matching in 
> Python rather than the overly terse, cryptic regular expression mini-
> language.
> 
> I haven't tested my function version, but I'm 95% sure that it is
> correct. 
> It trickiest part of it is the logic about splitting around ampersands.
> And 
> I'll cheerfully admit that it isn't easy to extend to (say) "ampersand,
> or 
> at signs". But your regex solution:
> 
> r"^[A-Z\s&]+$"
> 
> is much smaller and more compact, but *wrong*. For instance, your regex 
> wrongly accepts both "&&&&&" and "      " as valid strings, and wrongly 
> rejects "ΔΣΘΛ". Your Greek customers will be sad...

Meh. You have a pedantic definition of wrong. Given the inputs, it
produced right output. Very often that's enough. Perfect is the enemy of
good, it's said. 

There's no situation where "&&&&&" and "     " will exist in the given
dataset, and recognizing that is important. You don't have to account
for every bit of nonsense. 

If the OP needs a unicode-aware solution that redefines "A-Z" as perhaps
"\w" with an isupper call. Its still far simpler then you're suggesting.

-- 
Stephen Hansen
  m e @ i x o k a i . i o

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Whittle it on down DFS <nospam@dfs.com> - 2016-05-05 00:58 -0400
  Re: Whittle it on down Stephen Hansen <me+python@ixokai.io> - 2016-05-04 22:39 -0700
    Re: Whittle it on down DFS <nospam@dfs.com> - 2016-05-05 08:44 -0400
    Re: Whittle it on down DFS <nospam@dfs.com> - 2016-05-05 19:31 -0400
      Re: Whittle it on down Peter Otten <__peter__@web.de> - 2016-05-06 09:45 +0200
        Re: Whittle it on down DFS <nospam@dfs.com> - 2016-05-06 09:58 -0400
          Re: Whittle it on down DFS <nospam@dfs.com> - 2016-05-06 10:41 -0400
            Re: Whittle it on down Peter Otten <__peter__@web.de> - 2016-05-06 17:44 +0200
              Re: Whittle it on down DFS <nospam@dfs.com> - 2016-05-06 18:43 -0400
      Re: Whittle it on down alister <alister.ware@ntlworld.com> - 2016-05-06 10:01 +0000
  Re: Whittle it on down Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-05-05 08:53 +0300
    Re: Whittle it on down DFS <nospam@dfs.com> - 2016-05-05 08:57 -0400
  Re: Whittle it on down Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-05-05 16:04 +1000
    Re: Whittle it on down Stephen Hansen <me+python@ixokai.io> - 2016-05-04 23:46 -0700
      Re: Whittle it on down Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-05-05 17:04 +1000
        Re: Whittle it on down Stephen Hansen <me+python@ixokai.io> - 2016-05-05 00:34 -0700
          Re: Whittle it on down Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-05-05 18:41 +1000
            Re: Whittle it on down Random832 <random832@fastmail.com> - 2016-05-05 09:13 -0400
              Re: Whittle it on down Steven D'Aprano <steve@pearwood.info> - 2016-05-06 03:13 +1000
      Re: Whittle it on down Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-05-05 17:36 +1000
        Re: Whittle it on down Peter Otten <__peter__@web.de> - 2016-05-05 10:17 +0200
          Re: Whittle it on down Steven D'Aprano <steve@pearwood.info> - 2016-05-06 01:39 +1000
        Re: Whittle it on down Random832 <random832@fastmail.com> - 2016-05-05 09:21 -0400
          Re: Whittle it on down Steven D'Aprano <steve@pearwood.info> - 2016-05-06 04:03 +1000
            Re: Whittle it on down Random832 <random832@fastmail.com> - 2016-05-05 14:52 -0400
            Re: Whittle it on down Stephen Hansen <me+python@ixokai.io> - 2016-05-05 12:09 -0700
        Re: Whittle it on down Stephen Hansen <me+python@ixokai.io> - 2016-05-05 06:32 -0700
          Re: Whittle it on down DFS <nospam@dfs.com> - 2016-05-05 10:36 -0400
          Re: Whittle it on down Steven D'Aprano <steve@pearwood.info> - 2016-05-06 03:43 +1000
            Re: Whittle it on down Stephen Hansen <me+python@ixokai.io> - 2016-05-05 11:55 -0700
        Re: Whittle it on down Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-05-05 20:49 +0300
          Re: Whittle it on down Steven D'Aprano <steve@pearwood.info> - 2016-05-06 04:14 +1000
            Re: Whittle it on down Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-05-05 21:27 +0300
              Re: Whittle it on down Random832 <random832@fastmail.com> - 2016-05-05 14:54 -0400
              Re: Whittle it on down Steven D'Aprano <steve@pearwood.info> - 2016-05-06 10:57 +1000
                Re: Whittle it on down Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-05-06 07:19 +0300
    Re: Whittle it on down DFS <nospam@dfs.com> - 2016-05-05 08:31 -0400
      Re: Whittle it on down Steven D'Aprano <steve@pearwood.info> - 2016-05-06 03:54 +1000
        Re: Whittle it on down DFS <nospam@dfs.com> - 2016-05-05 17:36 -0400
      Re: Whittle it on down Stephen Hansen <me+python@ixokai.io> - 2016-05-05 11:56 -0700
        Re: Whittle it on down DFS <nospam@dfs.com> - 2016-05-05 17:45 -0400

csiph-web