I have a code that with two lists of dictionaries, and should make a final dictionary based on the comparing of two lists.
This is the code:
list_a = [
{'e1':20},
{'e1':11.2},
{'e1':20.33},
{'e1':19.34},
{'e1':18.2}
]
list_b = [
{'id': 1, 'e1':20, 'status':True},
{'id': 2, 'e1':11.2, 'status':False},
{'id': 3, 'e1':20.33, 'status':True}
]
mydict = {}
for b in list_b:
mydict.setdefault(b['id'], {})
if b['status']:
for a in list_a:
if b['e1'] - a['e1'] > 1:
mydict[b['id']] = b['e1'] - a['e1']
Just wondering if you have any solution to make this code more efficient (both speed and space aspects)?