Ravi 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?

Follow the link to the cookbook and read Andrew Dalke's comment ;) 
To spell it out:

>>> class D(dict):
...     def __missing__(self, key):
...             result = self[key] = D()
...             return result
...
>>> d = D()
>>> d["a"]["b"]["c"] = 42
>>> d
{'a': {'b': {'c': 42}}}

This is not only simpler, it should also give you faster lookup when the key 
already exists.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to