title: How to access all dictionaries within a dictionary where a specific key has a particular value
body: <p>I have a dictionary of dictionaries, with each nested dictionary having the exact same keys, like this:</p>
  
  <pre><code>all_dicts = {'a':{'name': 'A', 'city': 'foo'},
               'b':{'name': 'B', 'city': 'bar'},
               'c':{'name': 'C', 'city': 'bar'},
               'd':{'name': 'B', 'city': 'foo'},
               'e':{'name': 'D', 'city': 'bar'},
              }
  </code></pre>
  
  <p>How to I get a list (or dictionary) of all the dictionaries where <code>'city'</code> has value <code>'bar'</code>?</p>
  
  <p>The following code works, but isn't scalable:</p>
  
  <pre><code>req_key = 'bar'
  selected = []
  for one in all_dicts.keys():
      if req_key in all_dicts[one]:
      selected.append(all_dicts[one])
  </code></pre>
  
  <p>Say <code>'city'</code> can have 50,000 unique values and the dictionary <code>all_dicts</code> contains 600,000 values, iterating over the dictionary for every single value of <code>'city'</code> is not very efficient. </p>
  
  <p>Is there a scalable and efficient way of doing this?</p>