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

Ville Vainio ville at spammers.com
Wed Apr 6 02:53:15 EDT 2005


>>>>> "Bengt" == Bengt Richter <bokr at oz.net> writes:

    Bengt> I wonder if a dict with a general override hook for hashing
    Bengt> all keys would be useful.  E.g., a dict.__keyhash__ that
    Bengt> would take key as arg and default as now returning
    Bengt> key.__hash__() but that you could override. Seems like this

There would need to be an override hook for key comparison as well (I
suppose it always uses == operation now?). But yes, I think it would
be *much* more useful than any 'keytransform' feature - is there any
use for 'keytransform' feature apart from the uses that would be
better covered by hash/comparison hooks?

It would be lovely to have something like this in the stdlib (or
anywhere, for that matter). Think about the use cases for hashing via
by os.path.normcase, str.lower...

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



More information about the Python-list mailing list