regex question

Slawomir Nowaczyk slawomir.nowaczyk.847 at student.lu.se
Fri Aug 4 09:55:51 EDT 2006


On Thu, 03 Aug 2006 22:10:55 +0100
Gabriel Murray <gabriel.murray at gmail.com> wrote:

#> Hello, I'm looking for a regular expression ....

  Some people, when confronted with a problem, think "I know, I'll
  use regular expressions." Now they have two problems.
                                   -- Jamie Zawinski

Therefore:

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.

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

A mind is like a parachute. It doesn't work unless it's open.




More information about the Python-list mailing list