Extending dict (dict's) to allow for multidimensional dictionary

Javier nospam at nospam.com
Mon Mar 7 02:06:20 EST 2011


Looks a good idea.  I use this kind of "recursive dicts" to represent
tree like datastruct in python.  Like:

car["ford"]["taurus"]["price"]=...
car["toyota"]["corolla"]["mpg"]=...
car["toyota"]["corolla"]["price"]=...


It would be good if it could be combined with class2dict (converting
dict elemnets into attributes of a class/instance), 

http://vsbabu.org/mt/archives/2003/02/13/joy_of_python_classes_and_dictionaries.html

so the former would look a bit nicer:

car.toyota.corolla.mpg=...
car.toyota.corolla.price=...

Does anybody have  another idea for representing tree-like data?  Is
there another type for trees in python?



Ravi <ra.ravi.rav at gmail.com> wrote:
> I found a solution here:
> 
> http://parand.com/say/index.php/2007/07/13/simple-multi-dimensional-dictionaries-in-python/
> 
> Please tell how good is it?



More information about the Python-list mailing list