Efficient Data Structure Questions

Jeff Layton jeffrey.b.layton at lmco.com
Sun Aug 25 08:10:58 EDT 2002


Good morning,

   I'm struggling with a data structure design problem.
It basically boils down to a list of dictionaries or a dictionary
of lists.
   Here's the basic scenario. I have 3 keys I need to track,
'key1', 'key2', 'key3'. Now I could organize the data using
a list of dictionaries like the following:

FM.keyords=[]

dummy={}
dummy['key1']="string1"
dummy['key2']=0
dummy['key3']=[1, 2, 3, 4, 5]
FM.keywords.append(dummy)

dummy={}
dummy['key1']="string2"
dummy['key2']=1
dummy['key3']=[6, 7, 8, 9, 10]
FM.keywords.append(dummy)

...

(BTW, FM is a 'Borg' class).
   The other way is to something like this.

FM.keywords={}

FM.keywords['key1']=["string1", "string2", ... ]
FM.keywords['key2']=[0, 1, ... ]
FM.keywords['key3']=[[1.2.3.4.5],[6,7,8,9,10],... ]

   I need to search through 'key1' for a match to a string and
then get the 'key2' and 'key3' data associated with the
matched value of 'key1'.
   Does anyone have any suggestions as to the most efficient
data structure? (I like efficiency but I also like ease of coding).
Can anyone explain why one is better than the other (I know
that's subjective, but I'm looking to learn something from
this :)

TIA,

Jeff


--

Jeff Layton
Senior Engineer
Lockheed-Martin Aeronautical Company - Marietta
Aerodynamics & CFD
Phone: 770-494-8341
Fax:   770-494-3055
email: jeffrey.b.layton at lmco.com






More information about the Python-list mailing list