title: python setdefault in setdefault behavior
body: <p>I tries to understand how nested setdefault works in code. I know how the basic setdefault  works but I have a problem with figuring out such an code:</p>
  <p>there are no keys in d, why both keys and values are added? &quot;333&quot; not in d so we're going to defult value d.setdefault(&quot;444&quot;,[]) -&gt; we put a &quot;444&quot; key with a value [], setdefault return [] which we insert to &quot;333&quot; key which is returned by first setdefault and append is made(why for both new keys, I thought only for &quot;333&quot;)</p>
  <pre><code>d = {'111': ['aaa', 'bbb'], '222': ['ccc']}
  d.setdefault(&quot;333&quot;, d.setdefault(&quot;444&quot;,[])).append(&quot;ddd&quot;) 
  {'111': ['aaa', 'bbb'], '222': ['ccc'], '444': ['ddd'], '333': ['ddd']}
  </code></pre>
  <p>first is already in d, &quot;ddd&quot; is appended to the existing &quot;111&quot; key but why is there a new key &quot;444&quot;?</p>
  <pre><code>d = {'111': ['aaa', 'bbb'], '222': ['ccc']}
  d.setdefault(&quot;111&quot;, d.setdefault(&quot;444&quot;,[])).append(&quot;ddd&quot;) 
  {'111': ['aaa', 'bbb', 'ddd'], '222': ['ccc'], '444': []}
  </code></pre>
  <p>first and the second key is already in d, only first updated?</p>
  <pre><code>d = {'111': ['aaa', 'bbb'], '222': ['ccc']}
  d.setdefault(&quot;111&quot;, d.setdefault(&quot;222&quot;,[])).append(&quot;ddd&quot;) 
  {'111': ['aaa', 'bbb', 'ddd'], '222': ['ccc']}
  </code></pre>
  <p>second is in d,..?</p>
  <pre><code>d = {'111': ['aaa', 'bbb'], '222': ['ccc']}
  d.setdefault(&quot;333&quot;, d.setdefault(&quot;222&quot;,[])).append(&quot;ddd&quot;) 
  {'111': ['aaa', 'bbb'], '222': ['ccc', 'ddd'], '333': ['ccc', 'ddd']} 
  </code></pre>
  <p>thanks for the explanation</p>