title: Can I edit dictionaries created by dictreader in python
body: <p></p>
  
  <p>
  </p>
  
  <p>
  </p>
  
  <p>I am trying to edit values in dictionaries created by dictreader. If I understand this correctly, it creates a list of dictionaries. This part is working fine. However, I&#39;d like to change some of the values for the key:value pairs in certain dictionaries and this is not functioning the way I expect. After I finish editing the values, my dictreader object seems to be completely empty. </p>
  
  <p>To deal with this, I make an empty list (elis) and then fill it with all the dictionaries that were in the dictreader object. </p>
  
  <p>My code follows:</p>
  
  <pre><code>import csv
  import numpy as np
  import pandas as pd
  
  # Load the csv into a dictreader object
  elistable = csv.DictReader(open(&amp;quot;./elispotable.csv&amp;quot;, &amp;#39;rU&amp;#39;))
  
  # This code will print all the dictionaries when uncommented
  # for item in elis:
  #   print item
  
  # Create an empty list 
  elis=[]
  
  #Note that the dicts have keys including &amp;#39;Control&amp;#39; and &amp;#39;Peptide Id&amp;#39; 
  
  for item in elistable:
      if item[&amp;#39;Control&amp;#39;]==&amp;#39;Neg&amp;#39;:
          item[&amp;#39;Peptide Id&amp;#39;]=&amp;#39;Neg&amp;#39;
      if item[&amp;#39;Control&amp;#39;]==&amp;#39;Pos&amp;#39;:
          item[&amp;#39;Peptide Id&amp;#39;]=&amp;#39;Pos&amp;#39;
      elis.append(item)
  
  #Elis is now full with all the dictionaries and correct values that were edited in the for loop
  
  dude=[]
  for item in elistable:
      dude.append(item)
  
  print dude
  </code></pre>
  
  <p>Dude is totally empty and if I try to run a for loop to print the dicts from elistable, nothing prints. It works before I run the for loop with if statements, but not after. It seems to be completely empty now.</p>
  
  <p>Is it possible to edit the values in the dictionaries created by the dictreader? Am I somehow overwriting them all?</p>
  
  <p></p>
  
  <p></p>