Case insensitive Dictionary?
dale at out-think.NOSPAMco.uk
Fri Sep 22 00:31:14 CEST 2000
Alex <cut_me_out at hotmail.com> wrote:
>> Can I do a case-insensitve has_key test or lookup on a dictionary
>> without taking a copy of the keys (which would kind of slow things
>> down a lot!) ?
>Not really. Your best bet is probably to write a class that keeps the
>keys in a case-insensitive form. E.g.
>from UserDict import UserDict
> def __setitem__(self, key, value):
> UserDict.__setitem__(self, key.lower(), value)
> def __getitem__(self, key):
> return UserDict.__getitem__(self, key.lower())
>This is untested, and uses Python2.0, but hopefully it gets the general
You're working well tonight!
I'll think on that one.
Business Technology Consultants
More information about the Python-list