Complex Nested Dictionaries

T. Earle tnospamwade at bmi.net
Thu Feb 19 18:53:19 EST 2004


To list,

I'm trying to figure out the best approach to the following problem:

I have four variables:
   1) headlines
   2) times
   3) states
   4) zones

At this time, I'm thinking of creating a dictionary, headlinesDB, that
stores different headlines and their associated time(s), state(s), and
zone(s). The complexity is that each headline can have one or more times,
one or more states, and one or more zones.  However, there can only be 1
zone per time, and 1 zone per state.  What is the best way to tackle this
particular problem?

Here's an example of the complexity:

Let's say we have a "High Wind Warning" for our headline or hazard.  In
addition, there are currently two "High Wind Warnings" in effect.  The first
goes from Tonight through Friday morning (i.e., I'll probably store the
begin/end times in seconds from 1/1/1970).  It affects three counties all in
the state of Oregon: ORZ047, ORZ048, and ORZ049.  The second High Wind
Warning is in effect from Friday at Noon through Friday evening.  It affects
two counties in two separate states:  ORZ044 in Oregon and WAZ028 in
Washington.  Here's the flow chart:

High Wind Warning --> time1 --> state1 --> zone1, zone2, zone3
                               |
                               --> time2 --> state1 --> zone4
                                              --> state2 --> zone5

Keep in mind, each headline or hazard can have multiple times.  Each time
will have one or more states with each state containing one or more zones.
Is there a better way than a dictionary.  As mentioned above, the headline
or hazard is the key I'll be extracting all the information from.

Thanks in advance,

Tom





More information about the Python-list mailing list