Nested Dicts

D'Arcy J.M. Cain darcy at druid.net
Sat Dec 5 11:24:40 EST 2009


On Sat, 5 Dec 2009 10:52:10 -0500
Victor Subervi <victorsubervi at gmail.com> wrote:
> Hi;
> I have the following error:
> 
>  /var/www/html/angrynates.com/cart/catTree.py in
> getChildren(levelDict={'cat3': {}}, level=0)
>    23   if level > MAXLEVEL:
>    24     return  #possibly the data has a cycle/loop
>    25   for (nm, dt) in levelDict: ### ERROR HERE

Yes, you are tring to assign to two variabels but levelDict is a single
object, a dictionary with a single element which is another
dictionary.  If, as I assume, nm and dt (very poor variable names,
especially when you are asking others to help you debug) refer to name
and data by which you mean key and value from the dictionary then
perhaps you really want this.

  for key, val in levelDict.items():
     ...

-- 
D'Arcy J.M. Cain <darcy at druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



More information about the Python-list mailing list