Help with regex needed
D'Arcy J.M. Cain
darcy at druid.net
Tue Apr 12 08:50:03 EDT 2011
On Tue, 12 Apr 2011 15:06:25 +0300
Yuri Slobodyanyuk <yuri.slobodyanyuk at gmail.com> 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() == str(time_tuple).strip(' \t\n\r') and
> nnn.split() == str(time_tuple).strip(' \t\n\r') and nnn.split()
> == str(time_tuple).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) # strip() not really needed here
mon = str(time_tuple)
day = str(time_tuple)
for nnn in [x.split() for x in hhh]:
if nnn == mon and nnn = day and nnn = 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 druid.net> | 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.
More information about the Python-list