[Tutor] dictionary entries within dictionary

Paul Tremblay phthenry@earthlink.net
Tue Apr 8 01:53:01 2003

On Mon, Apr 07, 2003 at 07:06:43PM -0700, Jeff Shannon wrote:
> It might help to think of your nested dictionaries as a tree.  Each item 
> that's another dictionary is a twig, and items within the 
> most-deeply-nested dictionaries (such as your att:value pair) are 
> leaves.  (Try sketching out the structure, like you'd see for a family 
> tree.)  Assignment, like your original code tries to do, can only create 
> new leaves, not new twigs.  You have to build those twigs before you can 
> add leaves to them.  (To stick with the family tree example, you need to 
> create children before those new children can have grandchildren...)

Thanks. This makes sense. 

Using nested dictionaries is very tricky. I have to extract something
from the big dictionary to make a temporary dictionary, then make a
smaller dictionary to add to that, and finally add the whole thing to
the permanent dictionary. It is too bad one can't directly assign
values, as I was trying to do.

(In perl, one has to store nested structures as referenes, and then
dereference them--which is even trickier.)



*Paul Tremblay         *