title: Dictionary to CSV file: Ordering of columns
body: <p>I am trying to export a list of dictionaries to a .csv file:</p>
  
  <pre><code>keys = hist[0].keys()
  with open(file, 'wt') as output_file:
      dict_writer = csv.DictWriter(output_file, keys, lineterminator='\n')
      dict_writer.writeheader()
      dict_writer.writerows(hist)
  </code></pre>
  
  <p>I want the last key in the dictionary to be the first key in the column.</p>
  
  <p>My list of dictionaries (hist) is: </p>
  
  <pre><code>[{'RSD': '-', 'GBP': '0.500409', 'Date': '2008-04-05'}, 
   {'RSD': '-', 'GBP': '0.500409', 'Date': '2008-04-06'}, 
   {'RSD': '-', 'GBP': '0.50331', 'Date': '2008-04-07'}, 
   {'RSD': '-', 'GBP': '0.507939', 'Date': '2008-04-08'},
  ...
  </code></pre>
  
  <p>Which I got by:</p>
  
  <pre><code>for x in dates:
      l = {}
      for y in currs:
          try:
              m = exrates.get_exrates(x)[y]
          except KeyError:
              m = '-'
          l[y] = m
      l['Date'] = x
      hist.append(l)
  </code></pre>
  
  <p>How do I either change the ordering of the dictionary or change the ordering of the columns?</p>