title: Why does the order matter in this chained assignment?
body: <p>As shown by the following two code snippets, the order of the chained assignment matters (i.e. <code>node = node[ch] = {}</code> is not equivalent to <code>node[ch] = node = {}</code>.</p>
  <pre><code>trie = {}
  node = trie
  for ch in &quot;word&quot;:
      if ch in node:
          node = node[ch]
      else:
          node = node[ch] = {} # chained assignment #1
  print(trie) # {}
  </code></pre>
  <pre><code>trie = {}
  node = trie
  for ch in &quot;word&quot;:
      if ch in node:
          node = node[ch]
      else:
          node[ch] = node = {} # chained assignment #2
  print(trie) # {'w': {'o': {'r': {'d': {}}}}}
  </code></pre>
  <p>Why does the order matter?</p>
  <hr />
  <p>According to <a href="https://stackoverflow.com/questions/7601823/how-do-chained-assignments-work">another SO question</a>, the chained assignment</p>
  <pre><code>a = b = c
  </code></pre>
  <p>is equivalent to:</p>
  <pre><code>tmp = c
  a = c
  b = c
  </code></pre>
  <p>and I verified that the equivalent forms produced the same behavior. I.e.</p>
  <pre><code>        # node = node[ch] = {} # chained assignment #1
          tmp = {}
          node = tmp
          node[ch] = tmp
  </code></pre>
  <p>leads to a <code>print(trie)</code> of <code>{}</code>.</p>
  <p>Meanwhile</p>
  <pre><code>        node[ch] = node = {} # chained assignment #2
          tmp = {}
          node[ch] = tmp
          node = tmp
  </code></pre>
  <p>leads to a <code>print(trie)</code> of <code>{'w': {'o': {'r': {'d': {}}}}}</code>.</p>