title: How do I write a yaml file from a dictionary with python?
body: <p>I have a csv file which containing data where the header contains keys and the cells contain values.  I would like to use python to create a yaml file from the contents of the csv file.  </p>
  
  <p>I created a dictionary of the K:V pairs; however, I am stuck trying to get the K:V pairs into the yaml file.</p>
  
  <p>The structure of the yaml must be:</p>
  
  <pre><code>key1: value1
  key2: value2
  key3:
    -  key4: value4
       key5: {key6: [value6]
  key7: value7
  key8: value8
  key9: value9
    -
    -
  ---
  </code></pre>
  
  <p>If I were to manually create these, I would have more than 1000 YAMLs so it's pretty time consuming and unrealistic.</p>
  
  <p>I am looking for any ideas your much more experienced people might have.</p>
  
  <p>I would really like the output to iterate through the dictionary to create a huge listing of YAMLs like below:</p>
  
  <pre><code>key1: value1
  key2: value2
  key3:
    -  key4: value4
       key5: {key6: [value6]
  key7: value7
  key8: value8
  key9: value9
    -
    -
  ---
  key1: value1
  key2: value2
  key3:
    -  key4: value4
       key5: {key6: [value6]
  key7: value7
  key8: value8
  key9: value9
    -
    -
  ---
  key1: value1
  key2: value2
  key3:
    -  key4: value4
       key5: {key6: [value6]
  key7: value7
  key8: value8
  key9: value9
    -
    -
  ---
  key1: value1
  key2: value2
  key3:
    -  key4: value4
       key5: {key6: [value6]
  key7: value7
  key8: value8
  key9: value9
    -
    -
  ---
  </code></pre>
  
  <p>Sample Code:</p>
  
  <pre><code>import csv
  import yaml
  
  def csv_dict_list(variables_file) :
  
      reader=csv.DictReader(open(variables_file, 'r'))
      dict_list = []
      for line in reader:
          dict_list.append(line)
      return dict_list
  
  yaml_values = csv_dict_list(sys.argv[1])
  </code></pre>
  
  <p>No matter what I try after this, I can not get the desired output using yaml.load() or yaml.load_all().</p>