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

2005-04-01 Thread 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). d = CiDict([('Hi', 12),('hoho',13)]) d['hi'] 12 d.keys() ['Hi','hoho'] Note that 'Hi' preserved the

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

2005-04-01 Thread Daniel Dittmar
Ville Vainio wrote: 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). Store the original key together with the value and use a lowercase key for lookup. only a

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

2005-04-01 Thread Ville Vainio
Daniel == Daniel Dittmar [EMAIL PROTECTED] writes: Daniel Ville Vainio wrote: 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).

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

2005-04-01 Thread Daniel Dittmar
Ville Vainio wrote: Daniel == Daniel Dittmar [EMAIL PROTECTED] writes: Daniel Ville Vainio wrote: 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

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

2005-04-01 Thread Ron_Adam
On 01 Apr 2005 15:55:58 +0300, Ville Vainio [EMAIL PROTECTED] wrote: Daniel == Daniel Dittmar [EMAIL PROTECTED] writes: Daniel Ville Vainio wrote: I need a dict (well, it would be optimal anyway) class that stores the keys as strings without coercing the case to upper or

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

2005-04-01 Thread Raymond Hettinger
[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

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

2005-04-01 Thread Bengt Richter
On Fri, 01 Apr 2005 18:52:00 GMT, Raymond Hettinger [EMAIL PROTECTED] wrote: [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

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

2005-04-01 Thread Raymond Hettinger
[Bengt Richter] I wonder if a dict with a general override hook for hashing all keys would be useful. E.g., a dict.__keyhash__ that would take key as arg and default as now returning key.__hash__() but that you could override. Seems like this could potentially be more efficient than key

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

2005-04-01 Thread Bengt Richter
On Fri, 01 Apr 2005 23:04:42 GMT, Raymond Hettinger [EMAIL PROTECTED] wrote: [Bengt Richter] I wonder if a dict with a general override hook for hashing all keys would be useful. E.g., a dict.__keyhash__ that would take key as arg and default as now returning key.__hash__() but that you could

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

2005-04-01 Thread Raymond Hettinger
Taken together, these six attributes/methods could cover many wished for features for the 10% of the cases where a regular dictionary doesn't provide the best solution. You think as much as 10% ? Rounded up from 9.6 ;-) More important than the percentage is the clarity of the resulting code

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

2005-04-01 Thread Terry Reedy
Raymond Hettinger [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] More important than the percentage is the clarity of the resulting code and the avoidance of continous reinvention of workarounds. Separating tool features into a basic and an advanced version is common solution