In Python, I’ve got a list of dictionaries that looks like this:
matchings = [ {'id': 'someid1', 'domain': 'somedomain1.com'}, {'id': 'someid2', 'domain': 'somedomain2.com'}, {'id': 'someid3', 'domain': 'somedomain3.com'} ]
and, I have a variable:
the_id = 'someid3'
What’s the most efficient way to retrieve the domain value of the item?
You can use a list comprehension:
Which follows the format standard format of:
And basically encapsulates all the following functionality:
All that functionality is represented in a single line using list comprehensions.