Question: I need to write an expression that computes which keys are shared between the following two dictionaries and stores it in the variable named shared

I need to write an expression that computes which keys are shared between the following two dictionaries and stores it in the variable named shared_keys. In addition, need to write an expression that computes which values are shared between the two dictionaries and store the information in variable shared_values. (hint: use set intersection to store the group of shared keys in a Python set)
dict1={'a': 1,'b': 2,'c': 3,'d': 4,'e': 5}
dict2={'c': 10,'d': 20,'e': 30,'f': 40,'g': 50}
shared_values ={x:dict1[x] for x in dict1 if x in dict2}
My code is failing and I'm not sure where to go from here.
Please help!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!