Building and Transvering multi-level dictionaries
Max M
maxm at maxmcorp.dk
Mon Apr 3 16:25:02 EDT 2000
"Justin Sheehy" <dworkin at ccs.neu.edu> wrote in message
news:vnd1z4rtcdv.fsf at camelot-new.ccs.neu.edu...
> "maxm" <maxm at normik.dk> writes:
>
> > I'm in recursion hell here and have been trying to wring out the keys
for
> > almost two days now and can no longer think straight.
>
> You could certainly write a recursive function to gather all of the
> keys, and I was about to do so... but I decided that it wasn't worth
> the work. Instead, just make a couple of small changes to the class.
Hi Justin
Thanks for the code, but actually I think that I have found a much simpler
method for faking tree functionality in Python. I just use a tuple as a key
in a Dictionary:
#################################
theTree = {}
theTree[(1,)] = 'Max'
theTree[(2,)] = 'Gitte'
theTree[(2,4)] = 'Caroline'
theTree[(2,5)] = 'Clara'
theTree[(1,3)] = 'Magnus'
theTree[(1,3,6)] = 'unborn'
treeKeys= theTree.keys()
treeKeys.sort()
#print treeKeys
for key in treeKeys:
print (len(key)-1)*3*' ',theTree[key]
#################################
More information about the Python-list
mailing list