Feb-12-2018, 09:48 PM
Hello,
I have the below code, which is working fine, although I understand it is not the most efficient from a resource aspect.
I believe it is possible to implement it more elegantly with dictionary comprehension but I can't figure out how.
Thanks,
Gilles95
I have the below code, which is working fine, although I understand it is not the most efficient from a resource aspect.
I believe it is possible to implement it more elegantly with dictionary comprehension but I can't figure out how.
d ={'subkey':{'item1':{'num':'one','word':'alfa'},'item2':{'num':'two','word':'bravo'},'item3':{'num':'three','word':'charlie'} }} newdict = {} for key in d: for subkey in d[key]: if "l" in d[key][subkey]['word']: newdict[subkey] = d[key][subkey] print(newdict)Could someone help?
Thanks,
Gilles95