Dictionary that uses regular expressions
Peter Otten
__peter__ at web.de
Thu Aug 21 03:24:56 EDT 2003
I would leave the __getitem__() method alone and just add a
filterMatches(self, regexp) returning a ReDict or findMatches(self, regexp)
returning a list/iterator of values. That preserves the symmetry of
theDict[key] = value
value = theDict[key]
element access. It also makes client code more explicit as you can clearly
distinguish the reOn
x = theDict.filterMatches(bla)
and reOff
x = theDict[bla]
cases. Both reOn() and reOf() are no longer needed, plus you need not
overwrite __init__(), which preserves its expected (by users of dict)
behaviour.
Peter
More information about the Python-list
mailing list