title: Python - How do I return a dict key according to value in nested dict?
body: <p>I have a dictionary of dictionaries in Python.</p>
  
  <p>I would like a way to go through each dict of dict, check the value of the 'val' key in each dictionary then return the initial dictionary key where 'val' == 0.</p>
  
  <pre><code>dict = {
      1: {'x': 'a', 'val': 1},
      2: {'x': 'b', 'val': 1},
      3: {'x': 'c', 'val': 0},
      4: {'x': 'c', 'val': 0}
  }
  </code></pre>
  
  <p>I tried the following but that just return 3 and 4.</p>
  
  <pre><code>for itemid, iteminfo in data.items():
      for key in iteminfo:
          if iteminfo[key] == 0:
              print(str(itemid))
  </code></pre>
  
  <p>In the example above I would like 3 returned as it's the first instance where 'val' == 0.</p>