regex question

Slawomir Nowaczyk slawomir.nowaczyk.847 at student.lu.se
Sun Aug 6 05:41:20 EDT 2006


On Fri, 04 Aug 2006 14:55:34 -0700
John Machin <sjmachin at lexicon.net> wrote:

#> > def test(data):
#> >     format, index = 'abcd', 0
#> >     for c in data:
#> >         i = format.index(c)
#> >         if i > index+1:
#> >             return False
#> >         index = i
#> >     return index==format.index('d')
#> >
#> > Could be made faster if format was made a dictionary or if one wanted
#> > to compare characters directly. Writing (and profiling) left as an
#> > exercise for a reader.
#> 
#> Premature optimisation ....
#> 
#> #>>> test('bcd')
#> True
#> #>>>

Oooops... You are right. Should be 
    format, index = 'abcd', -1
of course. Thanks.

-- 
 Best wishes,
   Slawomir Nowaczyk
     ( Slawomir.Nowaczyk at cs.lth.se )

I believe that math illiteracy affects 7 out of every 5 people.




More information about the Python-list mailing list