title: Python - Get dictionary element in a list of dictionaries after an if statement
body: <p>How can I get a dictionary value in a list of dictionaries, based on the dictionary satisfying some condition? For instance, if one of the dictionaries in the list has the id=5, I want to print the value corresponding to the <code>name</code> key of that dictionary:</p>
  
  <pre><code>list = [{'name': 'Mike', 'id': 1}, {'name': 'Ellen', 'id': 5}]
  id = 5
  if any(m['id'] == id for m in list):
      print m['name']
  </code></pre>
  
  <p>This won't work because <code>m</code> is not defined outside the if statement.</p>