Update python dictionary (add another value to existing key)

Well you can simply use:

d['word'] = [1,'something']

Or in case the 1 needs to be fetched:

d['word'] = [d['word'],'something']

Finally say you want to update a sequence of keys with new values, like:

to_add = {'word': 'something', 'word1': 'something1'}

you could use:

for key,val in to_add.items():
    if key in d:
        d[key] = [d[key],val]

Leave a Comment