Complex Nested Dictionaries
has
has.temp at virgin.net
Sun Feb 22 13:59:51 EST 2004
"T. Earle" <tnospamwade at bmi.net> wrote in message news:<40354c35 at news.bmi.net>...
> 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?
Shake out non-essential complexity first. Not really up on relational
DBs and stuff, so take my attempts at table design with a pinch of
salt, but think I'd break your problem down something like this:
- Hazard Type Table
TYPE
High Wind Warning
Tornado Warning
Blizzard Warning
- Hazard Event Table
ID TYPE START END
ZONES
1 High Wind Warning 2004-03-01-22-00-00 2004-03-02-08-00-00
[ORZ047, ORZ048, ORZ049]
2 High Wind Warning 2004-03-02-12-00-00 2004-03-02-20-00-00
[ORZ044, WAZ028]
- Zone Table
ZONE STATE
ORZ044 Oregon
ORZ047 Oregon
ORZ048 Oregon
ORZ049 Oregon
WAZ028 Washington
Note this organises around individual hazard 'events', rather than
hazard types, making it easier to think see what's going on. Also,
because Zones already identify their States, there's no need to put
State info into hazard events. (State names, if you need them, can be
looked up separately.)
How you actually implement it - as a relational DB/a list of
HazardEvent instances stuffed into a list and brute-force searched via
list comprehensions/nested dicts and lists - really depends on how
you're going to manipulate it, how much flexibility/simplicity you
need, etc.
HTH
has
More information about the Python-list
mailing list