[Ville Vainio] > I need a dict (well, it would be optimal anyway) class that stores the > keys as strings without coercing the case to upper or lower, but still > provides fast lookup (i.e. uses hash table).
>>> class S(str):
def __hash__(self):
return hash(self.lower())
def __eq__(self, other):
return self.lower() == other.lower()
>>> d = {}
>>> d[S('ThE')] = 'quick'
>>> d[S('the')]
'quick'
>>> d
{'ThE': 'quick'}
Raymond Hettinger
--
http://mail.python.org/mailman/listinfo/python-list
