Complex Nested Dictionaries

T. Earle tnospamwade at bmi.net
Fri Feb 20 19:16:02 EST 2004


Russell,

> If you really only want to look up data by headline, then a dictionary
> of dictionaries or nested lists or some other kind of collection is easy
> and should suffice. For instance:
> warndict["High Wind Warning"] = (
>     (time1, {
>         state1: (zone1, zone2, zone3),
>         state2: (zone1, zone3),
>     }),
>     (time2, {...}),
> )

This definitely seems to be the structure I've been looking for or at least
have in mind.  Since I'm no expert, could offer some code examples on how to
create this structure on the fly?

> However, I suspect you will also want to be able to locate data by
> state, time or zone. If that is true, I really think you should consider
> storing the data in a relational database. It sounds like a perfect
> match to your problem. Python has some nice interfaces to various
> databases (including PostgreSQL and MySQL).

My first inclination was to go with a database; however, I thought about it
and concluded there may be too much variability each time the program is
executed.  For example, there will be times when there are no headlines;
other times, there will be numerous headlines.  Because of this variability,
the database would have to be created from scratch each time the program is
ran.  As a result, would a database still be the right choice?

I really appreciate your help and suggestions

T. Earle





More information about the Python-list mailing list