so basically i've written most of the code the only problem that i'm having is that the output that it gives me will not return a key with a different type. It will either return me keys with only int, or only str..for example
how i tested it is with:
and the out put is:
why doesn't it print out the 'x' key and value??
Code:
def merge_dictionaries(d1, d2):
'''Return a dictionary that is the result of merging the two given
dictionaries. In the new dictionary, the values should be lists. If a key
is in both of the given dictionaries, the value in the new dictionary should
contain both of the values from the given dictionaries, even if they are the
same. '''
d3 = {}
for c in d1:
if c in d2:
d3[c] = [d1[c], d2[c]]
else:
d3[c] = [d1[c]]
print d3
Code:
merge_dictionaries({ 1 : 'a', 2 : 9, -8 : 'w'}, {2 : 7, 'x' : 3, 1 : 'a'})
Code:
{-8: ['w'], 1: ['a', 'a'], 2: [9, 7]}
Comment