I am new to Python and am trying to write a function that will merge two dictionary objects in python. For instance
dict1 = {'a':[1], 'b':[2]}
dict2 = {'b':[3], 'c':[4]}
I need to produce a new merged dictionary
dict3 = {'a':[1], 'b':[2,3], 'c':[4]}
Function should also take a parameter “conflict” (set to True or False). When conflict is set to False, above is fine. When conflict is set to True, code will merge the dictionary like this instead:
dict3 = {'a':[1], 'b_1':[2], 'b_2':[3], 'c':[4]}
I am trying to append the 2 dictionaries, but not sure how to do it the right way.
for key in dict1.keys():
if dict2.has_key(key):
dict2[key].append(dict1[key])