title: How to loop over a dictionary with more than 3 sublevels of dictionaries inside it
body: <p>I am trying to loop over a dictionary where some keys have other dictionaries as values and some of those values are a key for a dictionary it has as a value. I am parsing a YAML file with over 5000 lines using pyyaml. When I load it, it creates a dictionary of everything in the file and breaks all the sub levels into dictionaries of their own.</p>
  
  <p>Here is what I am using now which gets me just the keys and values of things that are not dictionaries themselves but the keys and values of dictionaries:</p>
  
  <pre><code>for k1,v1 in dataMap['eng'].items():
      if type(dataMap['eng'][k1]) == dict:
          for k2, v2 in dataMap['eng'][k1].items():
              if type(dataMap['eng'][k1][k2]) == dict:
                  for k3, v3 in dataMap['eng'][k1][k2].items():
                      if type(dataMap['eng'][k1][k2][k3]) == dict:
                          print "key: {}, val: {}".format(k3, v3)
                      else:
                          print "key: {}, val: {}".format(k3, v3)
              else:
                  print "key: {}, val: {}".format(k2, v2)
      else:
          print "key: {}, val: {}".format(k1, v1)
  </code></pre>
  
  <p>Where 'eng' is the top most level that holds everything else within it in the YAML file. Below is a smple of the YAML file is am working with. The actual file has over 5000 lines in it though </p>
  
  <pre><code>eng:
    value1: 
      v1: USA
      v2: Canada
      v3: Mexico
    value2:
      value3:
         value4: "some text here"
         value5:
            value6: "some text here"
            value7: " some other text here"
         value8: "some text here"
      etc..
  </code></pre>
  
  <p>It goes on and on like this. Some keys just have values, some keys have dictionaries which themselves have dictionaries and this can go on a few levels deep.  I am just wondering if there is a better and easier way to do this then they way I am handling it with all the for loops and if statements checking if its a dict or not. In the end I would just need something like this:</p>
  
  <pre><code>v1: USA
  v2: Canada
  v3: Mexico
  value4: "some text here"
  value6: "some text here"
  value7: " some other text here"
  value8: "some text here"
  </code></pre>