(newbie) Array of dictionaries

Marty Brundage brundage at aimnet.com
Sat Oct 2 03:44:09 EDT 1999


I'd like to use an array of dictionaries but can't find any examples
of how it might be done.  e.g. I need an array of n dictionaries which
for dict[n] might allow an element to be expressed as dict[n][<key>],
although since the brackets seem to be reserved for keys, this syntax
illegal.  When I declare a separate array dicts[] and assign the
dictionaries, I find (for the same reason) that keys then don't work
on the dictionaries in the array.

The only work around is too awkward:

1) generate dictionaries
2) assign them to array dict[n]
..later to retrieve a dictionary...
3) assign dict[n] to dictionary
4) retrieve values as dictionary[m] 

Aside from all the unnecessary data shuffling, it seems inelegant so I
hope I'm missing an obvious solution.

Marty




More information about the Python-list mailing list