I would like to append to a dictionary for e.g
a={1:2}
a.update({2:4})
a.update({1,3})
I would like this to give
a ={1: (2,3), 2: 4}
How can this be done? There is no append. Update overwrites this as
{1: 3, 2: 4}
Please let me know
I would like to append to a dictionary for e.g
a={1:2}
a.update({2:4})
a.update({1,3})
I would like this to give
a ={1: (2,3), 2: 4}
How can this be done? There is no append. Update overwrites this as
{1: 3, 2: 4}
Please let me know
You could try something like this:
a = {1:2}
updates = [{2:4},{1:3}]
for dct in updates:
for key in dct:
if key in a:
a[key] = (a[key], dct[key])
else:
a[key] = (dct[key])
print(a)
#Gives: {1: (2, 3), 2: 4}