Newbie Dictionary Question

David Allen mda at idatar.com
Sat Mar 31 17:04:30 EST 2001


In article <jfmx6.7861$iU.1496746 at news1.rdc1.md.home.com>, "Gary Walker"
<borealis3 at home.com> wrote:

> 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...

A dictionary of dictionaries doesn't sound like too
bad of an idea.  Each "key" in the toplevel dictionary
would be the name of another dictionary.  In that
way, since keys are just strings, you can have a 
bunch of dictionaries with variable names. Like:

metadict = {}  # Empty top level dictionary
user_input = get_user_input()
metadict[user_input] = {}

Now you can populate metadict[user_input] with
a bunch of keys and values.  User_input might be
something from the user or more broadly just anything
that isn't know until runtime.  (Like the value of
a config varaible or whatever)

-- 
David Allen
http://opop.nols.com/
----------------------------------------
It's that time of year again, Defcon has descended upon us. Time to venture
to SYN City to see the lights, meet strange new people, and create new
blurs we later dub memories.
	-- Attrition.org



More information about the Python-list mailing list