I got a function call as this:

>>>def add_to_tree(root,value_string):
...    print "root is %s, value_string is %s" % (root, value_string)
...    for ch in value_string:
...      print "ch is %s" % ch
...      root = root.setdefault(ch,{})
...      print "root is", root
...      print "tree is", tree
>>> tree={}
>>> txt='abc'
>>> add_to_tree(tree,txt)
root is {}, value_string is abc
ch is a
root is {}
tree is {'a': {}}
ch is b
root is {}
tree is {'a': {'b': {}}}
ch is c
root is {}
tree is {'a': {'b': {'c': {}}}}

My question is:
(1) why root is always {}?
(2) why tree is {'a': {'b': {'c': {}}}}?
(3) why root isn't the same as tree? shouldn't they be the same because tree is 
argument passed as root?


Reply via email to