Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Pythong Dictionaries

Name: Anonymous 2011-03-16 18:21

I can't figure out how to do this, I tried recursion but I'm horrible at it. I wouldn't mind trying this out iteratively either, I'm not looking for what's best, I'm just trying to get the job done.

Say I have a dictionary with dictionaries in them, dicts = {'a':{'b':{'c':None}, how would I add a dictionary to it assuming I didn't know how many dictionaries in it was?

Name: Anonymous 2011-03-16 19:14

We've gone over data structures a bit in class, I don't have the best understanding of it because the prof isn't that good.

The actual function I'm trying to program is to add nodes to a tree (http://pastebin.com/MK6Bxvmt), but I'm not allowed to actually touch that file,it's in another file that uses it. The program will create trees based on whatever words you use and then store the word in the final node.

So if I had the words good and god the final product would look something like this:
{'g':{'o':{'d':None},{'o':{'d':None}}}})

The problem is that I don't know how to insert it this way, I'm not sure how to add key inside of x number of nested dictionaries.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List