title: update dictionary with dynamic keys and values in python
body: <p>I have a dictionary and I want to insert keys and values dynamically but I didn't manage to do it. The problem is that when I use the update method it doesn't add a pair but it deletes the previous values so I have only the last value when printing the dictionary 
  here is my code </p>
  
  <pre><code>i = 0
  for o in iterload(f):
      i=i+1
      mydic = {i : o["name"]}
      mydic.update({i : o["name"]})
      for k, v in mydic.items():
          print(k,v) 
  print(mydic)
  </code></pre>
  
  <p>f is a file that  i'm parsing with python code 
  as a result I get </p>
  
  <pre><code>{3: 'toto'}
  </code></pre>
  
  <p>which is the last element. is there a solution to have all the elements in my dictionary </p>
  
  <p>Thanks in advance </p>
  
  <p>I have another question </p>
  
  <p>Now I need to chek if an input value equals a key from my dictionary and if so I need to get the value of this key to continue parsing the file and get other informations.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>f = open('myfile','r')
  nb_name = input("\nChoose the number of the name :")
  
  for o in iterload(f):
      if o["name"] == mydic[nb_name]: 
          ...
  </code></pre>
  
  <p>I get a keyError</p>
  
  <pre><code>Traceback (most recent call last):
    File ".../test.py", line 37, in &lt;module&gt;
              if o["name"] == mydic[nb_name]: 
  KeyError: '1'
  </code></pre>
  
  <p>I don't understand the problem </p>