title: How do I correctly update nested dictionary values from a list in python?
body: <p>Please tell me what I am doing wrong!</p>
  <p>I wish to update entries in a dictionary from a list. Here are my (simplified) dictionary and list:</p>
  <pre><code>scene_dict = {0: {'speaker': None, 'listener': None}, 1: {'speaker': None, 'listener': None}}
  speaker_list = [&quot;Horatio&quot;, &quot;Marcellus&quot;]
  </code></pre>
  <p>I want to achieve the following result:</p>
  <pre><code>scene_dict = {0: {'speaker': &quot;Horatio&quot;, 'listener': None}, 1: {'speaker': &quot;Marcellus&quot;, 'listener': None}}
  </code></pre>
  <p>which would seem to be a straight-forward problem.</p>
  <p>In order to achieve the required result, I do the following:</p>
  <pre><code>for i, j in enumerate(scene_dict):
      scene_dict[j][&quot;speaker&quot;] = speaker_list[i]
  </code></pre>
  <p>which then gives the result I want, yeh!</p>
  <pre><code>print(scene_dict)
  </code></pre>
  <p>{0: {'speaker': 'Horatio', 'listener': None}, 1: {'speaker': 'Marcellus', 'listener': None}}</p>
  <p>So, &quot;where's the problem?&quot; you may ask. Well, in reality, the list of names that I am dealing with is much longer. So, my dictionary needs to be correspondingly much longer, but it has the exact same form. Naturally, I don't want to define my dictionary by writing it down explicitly. I need to generate it somehow, which I do as follows:</p>
  <pre><code>para_dict = {&quot;speaker&quot;: None, &quot;listener&quot;: None}
  scene_dict = {}
  
  for k in range(0,2):
      scene_dict[k] = para_dict 
  </code></pre>
  <p>This &quot;appears&quot; to work fine, and &quot;appears&quot; to give the exact same dictionary as I started with:</p>
  <pre><code>print(scene_dict)
  </code></pre>
  <p>{0: {'speaker': None, 'listener': None}, 1: {'speaker': None, 'listener': None}}</p>
  <p>However, when I now re-run the exact same for loop above on my (&quot;exact same&quot;) generated dictionary, in order to transfer the elements of my list to the values in the dictionary</p>
  <pre><code>for i, j in enumerate(scene_dict):
      scene_dict[j][&quot;speaker&quot;] = speaker_list[i]
  </code></pre>
  <p>I get a different (wrong) result:</p>
  <pre><code>print(scene_dict)
  </code></pre>
  <p>{0: {'speaker': 'Marcellus', 'listener': None}, 1: {'speaker': 'Marcellus', 'listener': None}}</p>
  <p>This time the for loop apparently equates both dictionary keys (&quot;speaker&quot;) at the same time with the first name in the list, and then both keys with the second name in the list, i.e. it equates both with Horatio and then both with Marcellus.</p>
  <p>I am mystified. What did I do wrong? How can I do better?</p>
  <p>Any advice would be appreciated.</p>