title: Conditional Python for loop based on YAML data
body: <p>I am new to Python so please bear with me. I am trying to figure out how to loop through a set of values in a YAML file. The file is parsed using PyYAML and then would need to be fed into the loop. Here is some YAML for example:</p>
  
  <p>dohicky.yml</p>
  
  <pre><code>---
  #Example file
  dohicky:
    "1":
      Stuff:
        - Data
        - Data
      Morestuff:
        - Data
        - Data
    "2":
      Stuff:
        - Data
        - Data
      Morestuff:
        - Data
        - Data
    "n":
      - Etc
  </code></pre>
  
  <p>First, I am pulling the contents of the YAML out.</p>
  
  <pre><code>import yaml
  f = open('dohicky.yml')
  dohicky = yaml.safe_load(f)
  f.close()
  </code></pre>
  
  <p>Now I just need either a for loop or a while loop to iterate through each numbered "id" under "dohicky".</p>
  
  <pre><code>for x in xrange(1, 2):
  </code></pre>
  
  <p>So obviously this would work, but is staticly defined for only 2 elements. Not sure how for example:</p>
  
  <pre><code>"do while" id = dohicky["dohicky"]["x"] is true. #Not code, just concept!
  </code></pre>
  
  <p>The other problem I am immediately running into is how to then create an object inside this loop. For example:</p>
  
  <pre><code>id(x) = dohicky(Pass other info from YAML to class) #Not code, just concept!
  </code></pre>
  
  <p>Unfortunately I am not familiar enough with Python yet (withPyYAML) to understand the syntax. Any help is MUCH appreciated!</p>
  
  <p><strong>* UPDATE *</strong>
  This is kinda sudo code, but you should understand what I am trying to do at least.</p>
  
  <pre><code>import yaml
  f = open('dohicky.yml')
  dohicky = yaml.safe_load(f)
  f.close()
  
  for x in dohicky["dohicky"]["x"]
          test = dohicky["dohicky"]["1"]["Stuff"]
          print test
  </code></pre>
  
  <p>In this test, I am just printing the output of "Stuff", but in reality, I need to create an object using that data.</p>