1.

Write a Program to combine two different dictionaries. While combining, if you find the same keys, you can add the values of these same keys. Output the new dictionary

Answer»

We can USE the COUNTER method from the COLLECTIONS module

from collections import Counterd1 = {'key1': 50, 'key2': 100, 'key3':200}d2 = {'key1': 200, 'key2': 100, 'key4':300}new_dict = Counter(d1) + Counter(d2)PRINT(new_dict)


Discussion

No Comment Found