Python program to match key values in two dictionaries.

In this python dictionary program, we will match key values in two dictionaries.

Steps to solve the program
  1. Take two dictionaries as input.
  2. Use for loop with an if-else statement to check whether keys from the first dictionary exist in the second dictionary or not.
  3. Print the respective output.
				
					dict1 = {'k1':'p','k2':'q','k3':'r'}
dict2 = {'k1':'p','k2':'s'}

for key in dict1:
    if key in dict2:
        print(f"{key} is present in both dictionaries")
    else:
        print(f"{key} is present not in both dictionaries")
				
			

Output :

				
					k1 is present in both dictionaries
k2 is present in both dictionaries
k3 is present not in both dictionaries
				
			

replace dictionary values with their average.

create a dictionary of keys a, b, and c where each key has as value a list from 1-5, 6-10, and 11-15 respectively.

Leave a Comment