Get the key of a minimum value from the following dictionary.
Given Input: sample_dict = {'Physics': 82,'Math': 65,'history': 75}
Expected output: Math
sample_dict = {'Physics':82,'Math':65,'History':75}
min_value = min(sample_dict.values())
for k,value in sample_dict.items():
if value == min_value:
print(k)
Math
Write a Python program to check if value 200 exists in the following dictionary.
Given Input: sample_dict = {'a': 100, 'b': 200, 'c': 300}
Expected output: 200 present in a dict
sample_dict = {'a':100,'b':200,'c':300}
if 200 in sample_dict.values():
print("200 present in a dict")
else:
print("200 is not present in the dict")
200 present in a dict
Merge two Python dictionaries into one
Given Input: dict1 = {'Ten': 10, 'Twenty': 20, 'Thirty': 30} dict2 = {'Thirty': 30, 'Fourty': 40, 'Fifty': 50}
Expected output: {'Ten': 10, 'Twenty': 20, 'Thirty': 30, 'Fourty': 40, 'Fifty': 50}
dict1 = {'Ten': 10, 'Twenty': 20, 'Thirty': 30}
dict2 = {'Thirty': 30, 'Fourty': 40, 'Fifty': 50}
dict3 = dict1.copy()
dict3.update(dict2)
print(dict3)
{'Ten': 10, 'Twenty': 20, 'Thirty': 30, 'Fourty': 40, 'Fifty': 50}