Write a python program to merging dictionaries
Using the merge ( | ) operator.
def myfun():
dict1 = {"Sateesh": 24,"siva": 14, "Ravi": 7}
dict2 = {"kumar": 45, "venkat": 67}
dict3 = dict1 | dict2
print(dict3)
if __name__=="__main__":
myfun()
Output:
{'Sateesh': 24, 'siva': 14, 'Ravi': 7, 'kumar': 45, 'venkat': 67}
Using the merge ( ** ) operator
def myfun():
dict1 = {"Sateesh": 24,"siva": 14, "Ravi": 7}
dict2 = {"kumar": 45, "venkat": 67}
dict3 = {**dict1, **dict2}
print(dict3)
if __name__=="__main__":
myfun()
Output:
{'Sateesh': 24, 'siva': 14, 'Ravi': 7, 'kumar': 45, 'venkat': 67}
More Questions
31 . Write a program to merging dictionaries
32 . Write a program to print swapping variables
33 . Write a python program to counting item occurrences
34 . Write a python program to print flatten a nested list
35 . Write a python program to Find the index of the largest number in the list
36 . Write a python program to Find the index of the smallest number in the list
37 . Write a python program to find absolute value of a number in the list
38 . Write a python program to adding a thousand separator
39 . Write a python program startswith and Endswith Methods
40 . Write a python program to print Nlargest numbers
41 . Write a python program to print Nsmallest numbers
For latest job updates join Telegram Channel: https://t.me/sateeshm