I\'ve looked through a few of the questions here and none of them seem to be exactly my problem. Say I have 2 dictionaries, and they are dict1
{\'A\': 25 ,
This is another way to do it, and will work regardless if the keys are present in only one or in both dictionaries.
def merge_dicts(dict_a, dict_b):
merged_dict = {key: [value] for key, value in dict_a.iteritems()}
for key, value in dict_a.iteritems():
try:
merged_dict[key].append(value)
except KeyError:
meeged_dict[key] = [value]
return ret_dict