Array of dict or lists or ....?

Pat Pat at junk.com
Mon Oct 6 19:45:07 EDT 2008


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

With each line I read in, I would create a hash entry and increment the 
number of enrolled students.

I wrote a routine in Perl using arrays of hash tables (but the syntax 
was a bear) that allowed me to read in the data and with those arrays of 
hash tables to arrays of hash tables almost everything was dynamically 
assigned.

I was able to fill in the hash tables and determine if any school class 
(e.g. Gym) had exceeded the number of max students or if no students had 
enrolled.

No, this is not a classroom project.  I really need this for my job. 
I'm converting my Perl program to Python and this portion has me stumped.

The reason why I'm converting a perfectly working program is because no 
one else knows Perl or Python either (but I believe that someone new 
would learn Python quicker than Perl) and the Perl program has become 
huge and is continuously growing.



More information about the Python-list mailing list