Array of dict or lists or ....?
Pat at junk.com
Tue Oct 7 01:45:07 CEST 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):
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
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
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