Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.043 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; "shouldn't": 0.07; 'loop.': 0.09; 'omit': 0.09; 'tuple': 0.09; 'read.': 0.12; 'subject:Help': 0.14; 'wrote:': 0.14; '+0300': 0.16; '425': 0.16; 'subject:regex': 0.16; 'great.': 0.16; 'tue,': 0.20; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:addr:python- list': 0.22; 'voting': 0.23; "what's": 0.24; 'chris': 0.27; 'testing': 0.28; 'thanks': 0.29; 'string': 0.29; 'mon': 0.29; 'this.': 0.30; 'cc:addr:python.org': 0.31; 'whitespace': 0.31; 'idea': 0.32; 'difficult': 0.35; 'running': 0.36; 'charset:us- ascii': 0.36; 'subject:with': 0.37; 'apr': 0.38; 'but': 0.38; 'used': 0.38; 'could': 0.39; 'header:Mime-Version:1': 0.39; 'split': 0.60; 'fact,': 0.60; 'subject:needed': 0.60; 'header :Message-Id:1': 0.62; '2011': 0.62; 'received:208': 0.62; 'url:net': 0.62; 'making': 0.62; 'year': 0.63; 'took': 0.64; 'here': 0.65; 'day': 0.66; 'democracy': 0.84; 'mins': 0.84 Date: Tue, 12 Apr 2011 08:50:03 -0400 From: "D'Arcy J.M. Cain" To: Yuri Slobodyanyuk Subject: Re: Help with regex needed In-Reply-To: References: X-Mailer: Sylpheed 3.1.0beta2 (GTK+ 2.22.0; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1302613207 news.xs4all.nl 41113 [::ffff:82.94.164.166]:36601 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3043 On Tue, 12 Apr 2011 15:06:25 +0300 Yuri Slobodyanyuk wrote: > Thanks everybody , and especially Chris - i used split and it took me 15 > mins to make it work :) That's great. One thing though... > for nnn in hhh: > if nnn.split()[2] == str(time_tuple[1]).strip(' \t\n\r') and > nnn.split()[4] == str(time_tuple[0]).strip(' \t\n\r') and nnn.split()[3] > == str(time_tuple[2]).strip(' \t\n\r') : You are running split() on the same string three times and running strip on the same time tuple each time through the loop. I know that you shouldn't optimize before testing for bottlenecks but this is just egrecious as well as making it more difficult to read. Consider this. year = str(time_tuple[0]) # strip() not really needed here mon = str(time_tuple[1]) day = str(time_tuple[2]) for nnn in [x.split() for x in hhh]: if nnn[2] == mon and nnn[3] = day and nnn[4] = year: If strip() were needed you could leave off the argument. The default is to strip all whitespace from both ends. In fact, read up on locales to see why it is a good idea to omit the argument. -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.