a string problem
Maric Michaud
maric at aristote.info
Tue Jun 13 12:11:53 EDT 2006
Le Mardi 13 Juin 2006 15:59, John Salerno a écrit :
> And I'm actually ashamed to admit that I know the RE way, but not the
> regular string manipulation way, if there is one!
eheh,
In [39]: import string
In [40]: sub, s1, s2 = 'string', 're string2, ,string1', 're string2, ,string'
In [41]: sub in [ e.strip(string.punctuation) for e in s1.split() ]
Out[41]: False
In [42]: sub in [ e.strip(string.punctuation) for e in s2.split() ]
Out[42]: True
> This seems like
> something easy enough to do without REs though.
Yes, but python way seems a little faster
python2.4 -mtimeit -s "import re" "re.match('\bstring\b', 're
string2, ,string1') and True"
100000 loops, best of 3: 7.3 usec per loop
python2.4 -mtimeit -s "import string" "'string' in [
e.strip(string.punctuation) for e in 're string2, ,string1'.split() ]"
100000 loops, best of 3: 6.99 usec per loop
--
_____________
Maric Michaud
_____________
Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
More information about the Python-list
mailing list