Case-insensitive dict, non-destructive, fast, anyone?

Ville Vainio ville at spammers.com
Fri Apr 1 12:38:12 CEST 2005


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).


>> d = CiDict([('Hi', 12),('hoho',13)])
>> d['hi']

12

>> d.keys()

['Hi','hoho']

Note that 'Hi' preserved the case. I imagine that 'Hi' and 'hi' would
need to share the same hash value in order for the lookup to be fast.

Anyone have a an implementation that I could use? Quick googling only
produced implementations that coerce all keys to lowercase.

-- 
Ville Vainio   http://tinyurl.com/2prnb



More information about the Python-list mailing list