caseless dictionary howto ?

Stef Mientki S.Mientki-nospam at
Tue Jun 19 23:07:49 CEST 2007

Evan Klitzke wrote:
> On 6/19/07, Stef Mientki <S.Mientki-nospam at> wrote:
>> hello,
>> I need to search a piece of text and make all words that are equal
>> (except their case) also equal in their case, based on the first 
>> occurrence.
>> So I'm using a dictionary to store names and attributes of objects.
>> As as I need to search on the caseless name (so I've choosen lowercase),
>> My dictionairy looks like this:
>>      self.procs [ "serial_hw_read"  ] = ( "Serial_HW_Read", "F", "++", T)
>> Is this really a good solution,
>> or are there better ways ?
> Since you want an almost dictionary, you should create a new class
> that inherits from dict and overloads the methods that you want to
> change.
but still one question.

Suppose I succeed in creating my own type, derived from dictionary,
I would be able to add/set a key like this:

     self.procs [ "Serial_HW_Read"  ] = ( "F", "++", T)

and now I can query the dictionary by

     self.procs.has_key ( "serial_hw_read")

but how do I get the original string "Serial_HW_Read" back ?

Stef Mientki

More information about the Python-list mailing list