title: Creating a dictionary from a csv file?
body: <p>I am trying to create a dictionary from a csv file. The first column of the csv file contains unique keys and the second column contains values. Each row of the csv file represents a unique key, value pair within the dictionary. I tried to use the <a href="https://docs.python.org/3/library/csv.html#csv.DictReader"><code>csv.DictReader</code></a> and <a href="https://docs.python.org/3/library/csv.html#csv.DictWriter"><code>csv.DictWriter</code></a> classes, but I could only figure out how to generate a new dictionary for each row. I want one dictionary. Here is the code I am trying to use:</p>
  
  <pre><code>import csv
  
  with open('coors.csv', mode='r') as infile:
      reader = csv.reader(infile)
      with open('coors_new.csv', mode='w') as outfile:
      writer = csv.writer(outfile)
      for rows in reader:
          k = rows[0]
          v = rows[1]
          mydict = {k:v for k, v in rows}
      print(mydict)
  </code></pre>
  
  <p>When I run the above code I get a <code>ValueError: too many values to unpack (expected 2)</code>. How do I create one dictionary from a csv file? Thanks.</p>