Expandable 2D Dictionaries?

Matimus mccredie at gmail.com
Fri Jul 6 12:06:02 EDT 2007


I'm not sure I completely understand what you want, but if you are
using Python2.5 defaultdict might be useful. Below is some example
code using defaultdict.


[code]
from collections import defaultdict

myvar = defaultdict(dict)

myvar["cat"]["paw"] = "SomeString"
myvar["dog"]["tail"] = "wags"
myvar["cat"]["tongue"] = "sand-paper"
myvar["mouse"]["likes"] = "cheese"
[/code]

The documentation can do a better job of explaining how this works
than I can: http://docs.python.org/lib/defaultdict-objects.html

-Matt




More information about the Python-list mailing list