Skip to content

Instantly share code, notes, and snippets.



Created Mar 2, 2010
What would you like to do?
import re
class ReDict(dict):
def __setitem__(self, key, value):
dict.__setitem__(self, re.compile(key), value)
def __getitem__(self, key):
return [v for k,v in self.items() if k.match(key)]
# Example:
rd = ReDict()
rd['^foo$'] = 1
rd['^bar*$'] = 2
rd['^bar$'] = 3
assert rd['foo'] == [1]
assert rd['barrrr'] == [2]
assert rd['bar'] == [2,3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.