Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!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.054 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'cc:addr:python-list': 0.09; 'python': 0.10; 'mathematics': 0.15; 'subject: \n ': 0.15; '97m': 0.16; 'whitespace.': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'pipe': 0.22; 'split': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'chris': 0.26; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'looks': 0.29; 'job:': 0.29; "i'm": 0.30; 'url:mailman': 0.30; "i'd": 0.31; 'another': 0.32; 'url:python': 0.33; 'lets': 0.33; 'symbol': 0.33; 'url:listinfo': 0.34; 'case,': 0.34; 'tue,': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'url:org': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'turn': 0.37; 'anything': 0.38; 'or,': 0.38; 'does': 0.39; 'url:mail': 0.40; 'jul': 0.72; 'sounds': 0.76; 'chrisa': 0.84; 'differently:': 0.84; 'victor': 0.84; 'joel': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=w7T4wEj1E3y4hwKaC/il/kJSCCjMc6jWqebZ1A7jzCI=; b=Y9eh0YyL/VBpq2rWt20b18TDagaA7myiM3Fqe9NJK1VGDMyGH5O97H42sK2d+8AdiZ 5T2cRHJgZtFbFRhdNUxS4hfR8s2AetSd+M1soa5Z0BMcWCVepuRJ4RYiVSGe51XGPV0I bkKEiLbbpYcfqW6McaiW66rhmH52zX3FUmrSmdEwwzqzXChnZYHN0NZYBYV20avDlZ+p ICmlPj/BbY6VKdZk/Pdq+vJChBnuXiOAfZw6ChS8AgOdjWPSNCck+I3lcLq+VbCraI5X 1QlSwsvIlmlxoLY+twuSeURCZVnRmX70ZYTBHptmHXX62/fBl5U5GtSo2l0Skxq/Ueng UKxg== MIME-Version: 1.0 X-Received: by 10.107.163.16 with SMTP id m16mr56150658ioe.31.1438133304868; Tue, 28 Jul 2015 18:28:24 -0700 (PDT) In-Reply-To: References: Date: Tue, 28 Jul 2015 21:28:24 -0400 Subject: Re: Split on multiple delimiters, and also treat consecutive delimiters as a single delimiter? From: Joel Goldstick To: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 1438137388 news.xs4all.nl 2824 [2001:888:2000:d::a6]:52816 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:94715 +1 Chris On Tue, Jul 28, 2015 at 8:08 PM, Chris Angelico wrote: > On Tue, Jul 28, 2015 at 11:55 PM, Victor Hooi wrote: >> I have a line that looks like this: >> >> 14 *0 330 *0 760 411|0 0 770g 1544g 117g 1414 computedshopcartdb:103.5% 0 30|0 0|1 19m 97m 1538 ComputedCartRS PRI 09:40:26 >> >> I'd like to split this line on multiple separators - in this case, consecutive whitespace, as well as the pipe symbol (|). > > Correct me if I'm misanalyzing this, but it sounds to me like a simple > transform-then-split would do the job: > > f.replace("|"," ").split() > > Turn those pipe characters into spaces, then split on whitespace. Or, > reading it differently: Declare that pipe is another form of > whitespace, then split on whitespace. Python lets you declare anything > you like, same as mathematics does :) > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com