title: Chained Method Calls in Python with dict
body: <p>I needed to flatten a dictionary today.  Meaning I wanted:</p>
  
  <pre><code>{'_id': 0, 'sub': {'a': 1, 'b':2}}
  </code></pre>
  
  <p>to become:</p>
  
  <pre><code>{'_id': 0, 'a':1, 'b':2}
  </code></pre>
  
  <p>So I thought I could be clever and pull off the following one-liner.</p>
  
  <h2>One-liner:</h2>
  
  <pre><code>x = dict(_id=0, sub=dict(a=1, b=2))
  y = x.pop('sub').update(x)  # incorrect result
  </code></pre>
  
  <p>This results in <code>y = None</code>.</p>
  
  <p>So I obviously resorted to:</p>
  
  <h2>Multi-Step:</h2>
  
  <pre><code>x = dict(_id=0, sub=dict(a=1, b=2))
  y = x.pop('sub')
  y.update(x)   # correct result
  </code></pre>
  
  <p>Setting "good expressive coding practices" asside for a moment, I would like to understand why the <strong>One-liner</strong> approach above yields <code>None</code>.  I would have thought that x.pop('sub') would have resulted in a temporary dict on a stack somewhere and the original x dict would be immediately updated.  Then the stack object would receive the next method in the chain which is the update.  This obviously does not seem to be the case.</p>
  
  <p>For the communities better understanding (and clearly mine) - how does python resolve the one-liner and result in <strong>None</strong>? </p>