I have two dictionaries:
union = {'a':'gamma','b':'beta','d':'theta'}
packaged = {'a':'alpha','b':'gamma','c':'alpha'}
I want:
packaged = {'a': 'alpha', 'b': 'gamma'}
Thus, I want to select only those keys from packaged which are present in union, along with their values.
I read this similar question and I am doing -
for k, v in list(packaged.items()):
if k not in union.keys():
del packaged[k]
print(packaged)
Which gives me the desired answer.
Is my method the most faster/ efficient way?, if not - is there any faster/ efficient way of doing this?