Help with regex needed

D'Arcy J.M. Cain darcy at
Tue Apr 12 08:50:03 EDT 2011

On Tue, 12 Apr 2011 15:06:25 +0300
Yuri Slobodyanyuk <yuri.slobodyanyuk at> 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 <darcy at>         |  Democracy is three wolves                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.

More information about the Python-list mailing list