title: Finding a parent key from a dict given an intermediate key using python
body: <p>I have a dictionary that looks like this:</p>
  
  <pre><code>d = {'dev':
          {&lt;dev1&gt;:
               {'mod':
                   {&lt;mod1&gt;:
                       {'port': [1, 2, 3]
                              }
                    }
                }
           &lt;dev2&gt;:
               {'mod':
                   {&lt;mod3&gt;:
                         {'port': [] }
                   }
               }
         }
    }
  </code></pre>
  
  <p>I want to be able to write a function, such that if i provide a search object such as 'mod1', it provides me the parent key as 'dev1'.</p>
  
  <p>I have searched all over and tried a bunch of things, but couldnt seem to get this to work. Any help will be appreciated!</p>
  
  <p>I have tried the stuff mentioned at the link below:</p>
  
  <p><a href="https://stackoverflow.com/questions/18819154/python-finding-parent-keys-for-a-specific-value-in-a-nested-dictionary">Python--Finding Parent Keys for a specific value in a nested dictionary</a></p>
  
  <p><a href="https://stackoverflow.com/questions/19214099/find-a-key-in-a-python-dictionary-and-return-its-parents">Find a key in a python dictionary and return its parents</a></p>