title: Using a loop to .setdefault on Dict Creates Nested Dict
body: <p>I'm trying to understand why </p>
  
  <pre><code>tree = {}
  
  def add_to_tree(root, value_string):
      """Given a string of characters `value_string`, create or update a
      series of dictionaries where the value at each level is a dictionary of
      the characters that have been seen following the current character.
      """
      for character in value_string:
          root = root.setdefault(character, {})
  
  add_to_tree(tree, 'abc')
  </code></pre>
  
  <p>creates <code>{'a': {'b': {'c': {}}}}</code></p>
  
  <p>while</p>
  
  <pre><code>root = {}
  
  root.setdefault('a', {})
  root.setdefault('b', {})
  root.setdefault('c', {})
  </code></pre>
  
  <p>creates <code>{'a': {}, 'b': {}, 'c': {}}</code></p>
  
  <p>What is putting us into the assigned dict value on each iteration of the loop? </p>