Efficient String Lookup?

Michael Hoffman m.h.3.9.1.without.dots.at.cam.ac.uk at example.com
Sat Oct 16 08:18:46 EDT 2004

Chris S. wrote:
> I have a number of strings, containing wildcards (e.g. 'abc#e#' where # 
> is anything), which I want to match with a test string (e.g 'abcdef'). 
> What would be the best way for me to store my strings so lookup is as 
> fast as possible?

If it were me, I would store them as compiled regular expressions.

See the re module documentation and use re.compile().

If you want a better solution, it might help if you supply a little more 
information about your problem and why this solution is unsuitable 
(maybe it is :]).
Michael Hoffman

More information about the Python-list mailing list