title: Loop through a nested python dictionary/list loaded from yaml
body: <p>Ok, this is probably stupid. Basically i'm trying to loop through my nested yaml-file and do stuff with for example every key-a value in my list. I have read alot and i'm able to loop through a nested dictionary without the list but I don't wan't to use unique key's for the nodes.</p>
  
  <p>This works:</p>
  
  <p>lev-0a:
    lev-1a:
      node1:
       key-a: '1'</p>
  
  <pre><code>node2:
   key-a: '2'
  </code></pre>
  
  <p>But when i'm trying to iterate a nested dict with "list" objects it fails.</p>
  
  <p>Yaml:</p>
  
  <pre><code>lev-0a:
    lev-1a:
      - key-a: '1'
        key-b: '2'
        key-c: '3'
        key-d:
          level-2:
            - key: 'a'
            - key: 'b'
            - key: 'c'
  
      - key-a: '7'
        key-b: '8'
        key-c: '9'
        key-d:
          level-2:
            - key: 'x'
            - key: 'y'
            - key: 'z'
  </code></pre>
  
  <p>Print settings from python:</p>
  
  <pre><code>{'lev-0a': {'lev-1a': [{'key-c': '3', 'key-b': '2', 'key-a': '1', 'key-d': {'level-2': [{'key': 'a'}, {'key': 'b'}, {'key': 'c'}]}}, {'key-c': '9', 'key-b': '8', 'key-a': '7', 'key-d': {'level-2': [{'key': 'x'}, {'key': 'y'}, {'key': 'z'}]}}]}}
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>env.settings_file = env.setting_path + '/settings.yaml'
  
  def load_settings(settings=env.settings_file):
      try:
          with open(settings) as stream:
              data = yaml.load(stream)
              return data
      except IOError as error:
          print ('File error: ' + str(error))
  
  
  def dev(settings=load_settings()):
  
      for k, v in settings['lev-0a']['lev-1a'].iteritems():
          print v['key-a']
          # do stuff with every key-a value
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>TypeError: list indices must be integers, not str
  </code></pre>
  
  <p>If I do this: </p>
  
  <pre><code>for k, v in settings['lev-0a']['lev-1a'][0].iteritems():
      print k,v
  </code></pre>
  
  <p>I will get:</p>
  
  <pre><code>key-c 3
  key-b 2
  key-a 1
  key-d {'level-2': [{'key': 'a'}, {'key': 'b'}, {'key': 'c'}]}
  </code></pre>
  
  <p>Thanks!</p>