Programming Examples

Python program to check if a dictionary is contained in another dictionary


Write a program to check if a dictionary is contained in another dictionary.

 

e.g., if

 

d1 = {1:11, 2:12}

d2 = {1:11, 2:12, 3:13, 4:15}

 

Then d1 is contained in d2.

Solution

dic1 = eval(input("Enter first dictionary :-"))
dic2 = eval(input("Enter second dictionary :-"))
count = 0
for i in dic1 :
      for j in dic2 :
            if i == j :
                  count += 1
if count == len(dic1):
      print("Then d1 is contained in d2.")
else :
      print("Then d1 is not contained in d2.")
Output

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz