I have a dictionary where the value is a list of dictionaries:
{ 'client1':
[
{ 'id': 123, 'name': 'test1', 'number': 777 },
{ 'id': 321, 'name': 'test2', 'number': 888 },
{ 'id': 456, 'name': 'test3', 'number': 999 }
],
...
}
and there is lots of entries keys by clientX
.
Now, in order to fetch entry with e.g. name == test2
, I loop through the list and check for name
value, something like this:
for l in d['client']:
if 'test2' in l['name']:
# process the entry
...
Is there a shorter/compact way to do such a lookup?