I think the most effective way to do it would be something like this:

for k, v in myDict2.iteritems():
    myDict1[k] = myDict1.get(k, ()) + v

But there isn't an update equivalent for what you're looking to do, unfortunately.

Answer from Nolen Royalty on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ check-and-update-existing-key-in-python-dictionary
Check and Update Existing Key in Python Dictionary - GeeksforGeeks
July 23, 2025 - For example, consider the dictionary d = {'name': 'Geek', 'rank': 10, 'city': 'Geek Town'}. If we want to update the 'rank' key to 'age', we check if 'rank' exists in the dictionary. If it does, we assign its value 10 to the new key 'age' and then remove 'rank' from the dictionary.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-dictionary-update-method
Python Dictionary update() method - GeeksforGeeks
February 16, 2026 - Example 1: In this example, new key-value pairs are added to the dictionary. ... Explanation: update({'y': 20}) adds new key 'y'. Example 2: In this example, the value of an existing key is modified.
Discussions

performance - Updating a python dictionary while adding to existing keys? - Stack Overflow
I'm looking for the most efficient and pythonic (mainly efficient) way to update a dictionary but keep the old values if an existing key is present. For example... myDict1 = {'1': ('3', '2'), '3':... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Update python dictionary (add another value to existing key) - Stack Overflow
Mind that the original dictionary uses scalars, not lists. 2017-01-24T10:39:11.967Z+00:00 ... and then use the following synthases to add any value to an existing key or to add a new pair of key-value: More on stackoverflow.com
๐ŸŒ stackoverflow.com
Equivalent of dictionary.update() but for appending when value is a collection?
There is not an exact equivalent, but there are things that are similar. I would suggest using a default dict: import collections d = collections.defaultdict(list) d[5].append(4) But if it had to be a standard dictionary, you could do d[ind] = d.get(ind, []) + [x] Note: the second will not modify existing lists in place, which may or may not be a problem. EDIT: Per u/commy2 's reply below, setdefault is better way if you're restricted to regular dictionaries - especially if your lists will be getting long so that copying them is nontrivial, or if it's important to modify the lists in place. More on reddit.com
๐ŸŒ r/learnpython
4
2
July 20, 2024
How to update the value of a key in a dictionary in Python? - Stack Overflow
I have a dictionary which represents a book shop. The keys represent the book title and values represent the number of copies of the book present. When books are sold from the shop, the number of c... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ dictionary โ€บ update
Python Dictionary update()
update() method updates the dictionary with elements from a dictionary object or an iterable object of key/value pairs.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-add-to-dictionary
How to Add and Update Python Dictionaries Easily | DigitalOcean
October 16, 2025 - The update() method overwrites the values of existing keys with the new values. The following example demonstrates how to create a new dictionary, use the update() method to add a new key-value pair and a new dictionary, and print each result: site = {'Website':'DigitalOcean', 'Tutorial':'How ...
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ 8 best ways to update non-existing key in python dict
8 Best Ways to Update Non-Existing Key in Python Dict - Be on the Right Side of Change
May 17, 2022 - To update a key in a dictionary ... you can check if it is present in the dictionary using the in keyword along with the if statement, and then update the key-value pair using subscript notation or update() method or the asterisk * operator...
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-dictionary-update
Python Dictionary Update
January 12, 2026 - The most common way I perform a dictionary update is by using the Python built-in method .update(). This method is incredibly versatile because it allows you to merge another dictionary or an iterable of key-value pairs into your current Python dictionary.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python dictionary update() method
Python Dictionary update() Method -
May 31, 2024 - Python dictionary update() method is used to update the dictionary using another dictionary or an iterable of key-value pairs(such as a tuple). If the key
Find elsewhere
๐ŸŒ
Data Science Parichay
datascienceparichay.com โ€บ home โ€บ blog โ€บ python add or update item in dictionary
Python Add or Update Item in Dictionary - Data Science Parichay
October 4, 2020 - The subscript notation, that is ... or updating a dictionary. update() is a dictionary function in python used to update a dictionary by changing the values of existing keys or adding new keys....
๐ŸŒ
KDnuggets
kdnuggets.com โ€บ 2023 โ€บ 02 โ€บ update-python-dictionary.html
How to Update a Python Dictionary - KDnuggets
February 20, 2023 - Learn how to update a Python dictionary using the built-in dictionary method update(). Update an existing Python dictionary with key-value pairs from another Python dictionary or iterable.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Add and Update an Item in a Dictionary in Python | note.nkmk.me
August 25, 2023 - You can pass a list of (key, value) pairs to update(). If a key in the list duplicates an existing key, it is overwritten with the value specified in the argument.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ dictionaries โ€บ .update()
Python | Dictionaries | .update() | Codecademy
May 13, 2025 - In Python, the .update() method adds key-value pairs from another dictionary or an iterable of key-value pairs to the target dictionary. If a key already exists, its value is updated; otherwise, a new key-value pair is added.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-update-dictionary-value-by-key
Python Update Dictionary Value by Key - GeeksforGeeks
July 23, 2025 - Each key must be unique, and you ... curly braces {}, and the key-value pairs are separated by colons. Python dictionaries are mutable, meaning you can modify them in place. In this article, I have explained how to update the value of an existing Key Dictionary....
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ dictionary_update.htm
Python dictionary update() Method
These key-value pairs are updated from another dictionary or iterable like tuple having key-value pairs. If the key value pair is already present in the dictionary, then the existing key is changed with the new value using update() method.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ standard-library โ€บ dict โ€บ update
Python dict update() - Update Dictionary | Vultr Docs
November 8, 2024 - This snippet ensures that while updating dict_d with defaults, it doesn't overwrite any existing keys. setdefault() is utilized to only add keys not already present in dict_d. The update() method in Python dictionaries simplifies the process of modifying dictionaries by adding or updating entries.
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ how to update a python dictionary?
How to Update a Python Dictionary? - AskPython
August 6, 2022 - In order to update the value of an associated key, Python Dict has in-built method โ€” dict.update() method to update a Python Dictionary.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ equivalent of dictionary.update() but for appending when value is a collection?
r/learnpython on Reddit: Equivalent of dictionary.update() but for appending when value is a collection?
July 20, 2024 -

I just learned about the update method while doing some work. I had been writing if statements to check if key is in .keys() for so long. Is there an equivalent for "add key: value if not already in dictionary, otherwise update the value"?

For example to replace:

if ind in collection.keys():
  collection[ind].append(x)
else:
  collection[ind] = [x]
Top answer
1 of 2
2
There is not an exact equivalent, but there are things that are similar. I would suggest using a default dict: import collections d = collections.defaultdict(list) d[5].append(4) But if it had to be a standard dictionary, you could do d[ind] = d.get(ind, []) + [x] Note: the second will not modify existing lists in place, which may or may not be a problem. EDIT: Per u/commy2 's reply below, setdefault is better way if you're restricted to regular dictionaries - especially if your lists will be getting long so that copying them is nontrivial, or if it's important to modify the lists in place.
2 of 2
1
I don't believe it's possible to do what you want with update(). The dictionary documentation for update() says: update([other]) Update the dictionary with the key/value pairs from other, overwriting existing keys. Note the emphasized text. The comment by u/ferricdonkey mentions using a defaultdict and that works perfectly to replace the code example that you showed. Like this: import collections collection = collections.defaultdict(list) collection[1] = [2] x = 42 ind = 1 # change to a key NOT in "collections" and run again collection[ind].append(x) print(collection) But your example isn't using update(). If you want to do what update() does but have it append to existing key values, you have to write a function to do that: import collections def ddict_update(ddict, upd): """Update a dictionary with either a dictionary or a sequence. Any existing key values are appended to, not replaced. """ if isinstance(upd, dict): for (key, val) in upd.items(): ddict[key].append(val) else: for (key, val) in upd: ddict[key].append(val) # make a test dictionary collection = collections.defaultdict(list) collection[1] = [2] update = {1: 42, 0: 42} # update with a dictionary ddict_update(collection, update) print(collection) update = [(3, 3), (1, 999)] # update with a sequence of tuples ddict_update(collection, update) print(collection) This does what you want, I think. The function can be simpler if you always update the dictionary with either another dictionary or a sequence.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-update-dictionary-with-other-dictionary
Update Dictionary with other Dictionary - Python - GeeksforGeeks
July 12, 2025 - update() is the most efficient way to update a dictionary in Python. This method modifies the original dictionary in place by adding keys from the second dictionary and updating the existing keys with new values.