Array of dict or lists or ....?

Barak, Ron Ron.Barak at lsi.com
Tue Oct 7 11:16:25 EDT 2008


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
...

Have an easy Yom Kippur,
Ron.

-----Original Message-----
From: Pat [mailto:Pat at junk.net]
Sent: Wednesday, October 08, 2008 04:16
To: python-list at python.org
Subject: Re: Array of dict or lists or ....?

Dennis Lee Bieber wrote:
> On Mon, 06 Oct 2008 19:45:07 -0400, Pat <Pat at junk.com> declaimed the
> following in comp.lang.python:
>
>> I can't figure out how to set up a Python data structure to read in
>> data that looks something like this (albeit somewhat simplified and contrived):
>>
>>
>> States
>>     Counties
>>       Schools
>>         Classes
>>            Max Allowed Students
>>            Current enrolled Students
>>
>> Nebraska, Wabash, Newville, Math, 20, 0 Nebraska, Wabash, Newville,
>> Gym, 400, 0 Nebraska, Tingo,  Newfille, Gym, 400, 0 Ohio, Dinger,
>> OldSchool, English, 10, 0
>
>       <snip>
>

> The structure looks more suited to a database -- maybe SQLite since
> the interface is supplied with the newer versions of Python (and
> available for older versions).

I don't understand why I need a database when it should just be a matter of defining the data structure.  I used a fictional example to make it easier to (hopefully) convey how the data is laid out.

One of the routines in the actual program checks a few thousand computers to verify that certain processes are running.  I didn't want to complicate my original question by going through all of the gory details (multiple userids running many processes with some of the processes having the same name).  To save time, I fork a process for each computer that I'm checking.  It seems to me that banging away at a database would greatly slow down the program and make the program more complicated.

The Perl routine works fine and I'd like to emulate that behavior but since I've just starting learning Python I don't know the syntax for designing the data structure.  I would really appreciate it if someone could point me in the right direction.




More information about the Python-list mailing list