Newbie Dictionary Question

Gary Walker borealis3 at home.com
Sat Mar 31 09:57:19 EST 2001


I *think* I want to do the following:

I want to create a list (this I'm able to do)
Then I want to dynamically create a dictionary for each item in the list,
add some keys (and values), and then put the dictionary in the list.

(This part is frustrating me, because my newbie python code is referencing
the SAME dictionary for each of the list indexes, this NOT what I want. I
want a new instance of a dictionary for each pass thru the list as I loop)

I want to do this because this way I can have an ordered list of key/value
pairs... at least that was my plan...

In other words:
How do I dynamically create a dictionary whose name is not known until
runtime?

Or, what's a better way to do this (i.e. create an ordered list of key/value
pairs)

Actually, they don't have to be ordered, so I suppose (thinking aloud here)
that I could use a dictionary of dictionaries, but again - it seems to me
that I'd need to dynamically create a dictionary whose name isn't known
until runtime...

Or am I missing the obvious? This is the most likely scenario :)

TIA,

Gary





More information about the Python-list mailing list