Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.060 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.01; 'string': 0.09; 'lawrence': 0.09; 'cc:addr:python-list': 0.11; '"by': 0.16; '"in': 0.16; 'a.py': 0.16; 'subject:Regular': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'tend': 0.24; 'cc:2**0': 0.24; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'received:209.85.217': 0.29; 'message-id:@mail.gmail.com': 0.30; 'you?': 0.31; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'received:209': 0.37; 'rather': 0.38; 'new': 0.61; 'reach': 0.63; 'subject:Search': 0.84; 'to:addr:yahoo.co.uk': 0.84; 'careful': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=9Pm59MODT4mIeRgay0R/2cok1NplG9zbUUfKI/fMq7M=; b=CBLlJGAd4Fh0GQK63eVcFWIotAkEn5LOjQZPRwHX6mONj738psQfyR8bu5y/EN+jTx FVwUQW6pvptmmR092jG8SR46SwWXHeAaHn/VNyNjlbr8PYWYzRd1iG+IgCvIA2MnXDLY nKpaRliTTYyaRZOipwx5A1x+4He1Cfwz5yR+Ygb1UtVL6OIRa1OosfiQw+dyf/Jl+Xlg ZcBDfbKy7j795fkgr0DYp6DjiZbCc5rYm6/ijcd/6CgQTrj4L1hnyoGCGXRqFje1AcjS /eg/F0XFsrwbCHQSgSHsTMcOJGbZQBuLJneZdC0bhJ5IqbYrrX0TmxJp3C/CqZWL7Hon xpWQ== X-Received: by 10.112.5.199 with SMTP id u7mr3525787lbu.67.1371330239759; Sat, 15 Jun 2013 14:03:59 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Joshua Landau Date: Sat, 15 Jun 2013 22:03:19 +0100 Subject: Re: Pattern Search Regular Expression To: Mark Lawrence Content-Type: text/plain; charset=UTF-8 Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371330247 news.xs4all.nl 16010 [2001:888:2000:d::a6]:44735 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48370 On 15 June 2013 11:18, Mark Lawrence wrote: > I tend to reach for string methods rather than an RE so will something like > this suit you? > > c:\Users\Mark\MyPython>type a.py > for s in ("In the ocean", > "On the ocean", > "By the ocean", > "In this group", > "In this group", > "By the new group"): > print(' '.join(s.split()[1:-1])) > > > c:\Users\Mark\MyPython>a > the > the > the > this > this > the new Careful - " ".join(s.split()) != s Eg: >>> " ".join("s\ns".split()) 's s' It's pedantry, but true.