How can I write a program in Python Dictionary that prints repeated keys values? -
this input:
dic1 = {'a':'usa', 'b':'canada', 'c':'france'} dic2 = {'c':'italy', 'd':'norway', 'e':'denmark'} dic3 = {'e':'finland', 'f':'japan', 'g':'germany’}
i want output below:
{'g': 'germany', 'e': [‘denmark’,’finland'], 'd': 'norway', 'c': ['italy’,'france', 'f': 'japan', 'b': 'canada', 'a': 'usa'}
that programing - think steps need desired results, , write code perform these steps, 1 @ time.
a funciton can it:
def merge_dicts(*args): merged = {} dct in args: key, value in dct.items(): if key not in merged: merged[key] = [] merged[key].append(value) return merged
Comments
Post a Comment