Scenario:
I have two dicts, one is the factory_dct and the other is the sold_dct
The scenario is that, exclude all the items from the factory_dct that are present in the sold_dct
The difference is that, the factory dict has a key where as the sold_dct has the key inside the day
The following snippet takes a very long time when the data is huge, is there anyway I can optimise this?
def update_fctr_dct(factory_dct, sold_dct, day):
for key in (set(factory_dct) & set(sold_dct)):
if day in sold_dct[key]:
sold_units = [d for d in factory_dct[key] for k, z in sold_dct[key][day].items() for z1 in z if
d['unit_id'] == z1['unit_id']]
if sold_units:
factory_dct[key] = [x for x in factory_dct[key] if x not in sold_units]
factory_dct = {k: v for k, v in factory_dct.items() if v}
else:
print("No units sold this day")