title: update python dictionary values and write result as json output
body: <p>I have a piece of code that loops through a python dictinary, graps the key/values needed and print them in a json format:</p>
  
  <p>my original dictionary looks like this:</p>
  
  <pre><code>"mydict": [ 
           {
              "Name": "test", 
              "number": "18", 
              "entity": 0
          }, 
          {
              "Name": "update", 
              "number": "25", 
              "entity": 3
          }, 
          {
              "Name": "manage", 
              "number": "8", 
              "entity": 5
          }
  ]
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>my_elements = resp.get('mydict')
  final= {}
  for item in my_elements :
      dic = {item.get('Name') : item.get('number'), 'entity' : item.get('entity')}
      output = json.dumps(dic, indent=4)
      print output
  </code></pre>
  
  <p>This is printing the expected output, however, when I try to write the output I get in a file I only get the last part of the answer and not the whole dictionary, this is what I get:</p>
  
  <pre><code>{
      "manage": 8,
      "entity": 5
  }
  </code></pre>
  
  <p>while I want to get:</p>
  
  <pre><code>{
      "test": 18,
      "entity": 0
  }
  {
      "update": 25,
      "entity": 3
  }
  {
      "manage": 8,
      "entity": 5
  }
  </code></pre>
  
  <p>This is the code I added hoping to get the needed output:</p>
  
  <pre><code>with open ('result.json','w') as outfile:
      json.dump(dic, outfile,)
  </code></pre>
  
  <p>But this returns the first output I do not desire. Thanks in advance for any help.</p>