Dictionary that uses regular expressions
Raymond Hettinger
vze4rx4y at verizon.net
Thu Aug 21 01:05:52 EDT 2003
"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.
Also, see if there are ways to change the API so that there
is a single return type. That would relieve the user of having
to test every call to see whether it got a collection of answers
or a specific answer. One idea is to have __getitem__ return
an iterator so that it doesn't matter where the number of matches
is zero, one, or many:
for value in rd['put may 7.5']
print value
Raymond Hettinger
More information about the Python-list
mailing list