Dictionary that uses regular expressions

Jack Diederich jack at performancedrivers.com
Tue Aug 26 10:29:14 EDT 2003


On Thu, Aug 21, 2003 at 05:05:52AM +0000, Raymond Hettinger wrote:
> "Erik Lechak" <prochak at netzero.net> wrote in message
> news:1f0bdf30.0308202049.7d251469 at posting.google.com...
> > Hello all,
> >
> > I wrote the code below.  It is simply a dictionary that uses regular
> > expressions to match keys.  A quick look at _test() will give you an
> > example.
> >
> > Is there a module that already does this?
> 
> Google may prove me wrong, but this looks like a new idea.
> 
> 
> > Is there a way and would it
> > be better to use list comprehension? (using python 2.3)
> >
> > Just looking for a better or more pythonic way to do it.
> 
> Try inheriting from UserDict.DictMixin instead of dict.
> 

Some months ago I started rewriting the C regexps module to allow for
matching pure-python string types[1].  The python class would just have
to define a method to get the next character and optionally a method
to say how much to backtrack on a match failure.  My use case was ternary
trees, instead of doing a lookup with a string key it would return
first or any matches of a regexp key.

Other people were doing heavy work on the regexp module so I'm waiting
for the 2.4 implementation to stabalize before I go back to it.

-jackdied

[1] http://mail.python.org/pipermail/python-dev/2003-April/034688.html






More information about the Python-list mailing list