You can use list comprehension :
domains = [matching['domain'] for matching in matchings if matching['id'] == the_id]
What follows the standard format format:
resulting_list = [item_to_return for item in items if condition]
And basically encapsulates all of the following functions:
domains = []
for matching in matchings:
if matching['id'] == the_id:
domains.append(matching['domain'])
All of these features are presented on a single line using lists.
source
share