Python dict.fromkeys return same id element
<p>When i do this on python i update all keys in one time.</p>

<pre><code>&gt;&gt;&gt; base = {}
&gt;&gt;&gt; keys = ['a', 'b', 'c']
&gt;&gt;&gt; base.update(dict.fromkeys(keys, {}))
&gt;&gt;&gt; base.get('a')['d'] = {}
&gt;&gt;&gt; base
{'a': {'d': {}}, 'c': {'d': {}}, 'b': {'d': {}}}
&gt;&gt;&gt; map(id, base.values())
[140536040273352, 140536040273352, 140536040273352]
</code></pre>

<p>If instead of <code>.get</code> i use <code>[]</code> operator this not happen:</p>

<pre><code>&gt;&gt;&gt; base['a']['d'] = {}
&gt;&gt;&gt; base
{'a': {'d': {}}, 'c': {}, 'b': {}}
</code></pre>

<p>Why?</p>

<p>I tried it with both Python 2.7.6 and 3.4.3. I get the same answer when either <code>get('a')</code> or <code>['a']</code> is used. Appreciate if you can verify this at your end. Python does object reuse. Thus, <code>dict.fromkeys()</code> reuses the same empty <code>dict</code> is to initialize. To make each one a separate object, you can do this:</p>

<pre><code>base.update(zip(keys, ({} for _ in keys)))
</code></pre>

python dictionary