Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #3043
| Date | 2011-04-12 08:50 -0400 |
|---|---|
| From | "D'Arcy J.M. Cain" <darcy@druid.net> |
| Subject | Re: Help with regex needed |
| References | <BANLkTinmYxe=EZBJL4QW7zp0X-3+nr9-sA@mail.gmail.com> <BANLkTimAkDCsif_cxax5v3zn6dgH5-P1bw@mail.gmail.com> <BANLkTi=sVE4Cntr7VhMK+0eshnLrd9+BBg@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.253.1302613207.9059.python-list@python.org> (permalink) |
On Tue, 12 Apr 2011 15:06:25 +0300
Yuri Slobodyanyuk <yuri.slobodyanyuk@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()[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@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.
Back to comp.lang.python | Previous | Next | Find similar
Re: Help with regex needed "D'Arcy J.M. Cain" <darcy@druid.net> - 2011-04-12 08:50 -0400
csiph-web