class Rhash proposal

Oliver Fromme olli at haluter.fromme.com
Wed Jul 14 13:55:56 EDT 2004


paolo veronelli <paolo_veronelli at yahoo.it> wrote:
 > class Rhash(dict):
 >        def __getitem__(rhash,key):
 >                if key not in rhash:
 >                        rhash[key]=Rhash()
 >                return dict.__getitem__(key)
 > 
 > Rhash lets us say:
 > 
 > Human=Rhash()
 > I=Rhash()
 > 
 > Human['isKindOf']['beast']=None
 > 
 > I['like']['mixing'][('smoking','thinking')]=True

You could simply write the indices into a sequence (tuple),
instead of stacking multiple dimensions of indices:

Human = {}
I = {}

Human[('isKindOf', 'beast')] = None

I[('like', 'mixing', ('smoking', 'thinking'))] = True

That would be easier and more efficient.  Can you provide
a real-world example where your Rhash approach offers a
real advantage?

Best regards
   Oliver

-- 
Oliver Fromme, Konrad-Celtis-Str. 72, 81369 Munich, Germany

``All that we see or seem is just a dream within a dream.''
(E. A. Poe)



More information about the Python-list mailing list