Building and Transvering multi-level dictionaries
Darrell
darrell at dorb.com
Tue Mar 21 00:54:52 EST 2000
[sblakey at freei.net]
> >
> You can simulate multi-level dictionaries with tuples:
> mydict = {}
> mydict['animal', 'mammal', 'cat'] = 'Enjoys sleeping in the sun'
> This makes the second part of your problem extremely simple:
> compundkey= ('animal', 'mammal', 'cat')
> description = mydict[compoundkey]
>
I like these all in one dictionary approaches to trees and use them my self.
Although I always forget to think of tuples for the keys.
In this case I wonder if it works as well as dictionaries with in
dictionaries. For instance what if you wanted a list of all animal:mammal:*
?
>From the code I posted:
print lookUp(dataDic,'animal.mammal')
{'cat': 'Enjoys sleeping in the sun', 'dog': 'Not your average hound'}
--Darrell
More information about the Python-list
mailing list