Help with regex needed
yuri.slobodyanyuk at gmail.com
Tue Apr 12 21:11:55 CEST 2011
Thanks for the insight, while this code will run once a week and
optimization isn't really a must here, it is
still a good idea not to leave half-baked code behind me, especially given
that it will be running on this server for the next 13 years ;)
I have one doubt though . Doesn't using the list comprehension here increase
number of loops per the same string ?
for nnn in [x.split() for x in hhh]:
My vision here is that after doing the comprehension it would look:
for nnn in [1st_field,2nd_field,3rd_filed,...,nth_filed]:
... and therefore would do number of loops equal to number of fields while
we really need just one ?
On Tue, Apr 12, 2011 at 3:50 PM, D'Arcy J.M. Cain <darcy at druid.net> wrote:
> 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
> > == 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.
Taking challenges one by one.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list