Array of dict or lists or ....?

Aaron "Castironpi" Brady castironpi at gmail.com
Tue Oct 7 18:41:44 CEST 2008


On Oct 7, 10:16 am, "Barak, Ron" <Ron.Ba... at lsi.com> wrote:
> Would the following be suitable data structure:
> ...
> struct = {}
> struct["Nebraska"] = "Wabash"
> struct["Nebraska"]["Wabash"] = "Newville"
> struct["Nebraska"]["Wabash"]["Newville"]["topics"] = "Math"
> struct["Nebraska"]["Wabash"]["Newville"]["Math"]["Max Allowed Students"] = 20
> struct["Nebraska"]["Wabash"]["Newville"]["Math"]["Current enrolled Students"] = 0
> ...

That's not quite right as stated.

>>> struct = {}
>>> struct["Nebraska"] = "Wabash"
>>> struct["Nebraska"]["Wabash"] = "Newville"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment




More information about the Python-list mailing list