๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_dictionary_update.asp
Python Dictionary update() Method
Python Tuples Access Tuples Update Tuples Unpack Tuples Loop Tuples Join Tuples Tuple Methods Tuple Exercises Code Challenge Python Sets ยท Python Sets Access Set Items Add Set Items Remove Set Items Loop Sets Join Sets Frozenset Set Methods Set Exercises Code Challenge Python Dictionaries
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ dictionary โ€บ update
Python Dictionary update()
Before we wrap up, letโ€™s put ... merge two dictionaries. Return the merged dictionary. For example, for inputs {'a': 1, 'b': 2} and {'c': 3, 'd': 4}, the output should be {'a': 1, 'b': 2, 'c': 3, 'd': 4}....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-dictionary-update-method
Python Dictionary update() method - GeeksforGeeks
October 22, 2018 - Returns: Does not return anything. It updates the dictionary. Example 1: In this example, new key-value pairs are added to the dictionary.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ home โ€บ python โ€บ python dictionary update
Python Dictionary Update
February 21, 2009 - Discover effective ways to update Python dictionaries with examples and detailed explanations to improve your coding skills.
๐ŸŒ
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
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-add-to-dictionary
How to Add and Update Python Dictionaries Easily | DigitalOcean
October 16, 2025 - The following example demonstrates how to create two dictionaries, use the update operator to append the second dictionary to the first dictionary, and then print the updated dictionary: site = {'Website':'DigitalOcean', 'Tutorial':'How To Add to a Python Dictionary', 'Author':'Sammy'} guests ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dictionaries_change.asp
Python - Change Dictionary Items
Python Tuples Access Tuples Update Tuples Unpack Tuples Loop Tuples Join Tuples Tuple Methods Tuple Exercises Code Challenge Python Sets ยท Python Sets Access Set Items Add Set Items Remove Set Items Loop Sets Join Sets Frozenset Set Methods Set Exercises Code Challenge Python Dictionaries
๐ŸŒ
KDnuggets
kdnuggets.com โ€บ 2023 โ€บ 02 โ€บ update-python-dictionary.html
How to Update a Python Dictionary - KDnuggets
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.
Find elsewhere
๐ŸŒ
Python Reference
python-reference.readthedocs.io โ€บ en โ€บ latest โ€บ docs โ€บ dict โ€บ update.html
update โ€” Python Reference (The Right Way) 0.1 documentation
Required. Either another dictionary object or an iterable of key:value pairs (iterables of length two). If keyword arguments are specified, the dictionary is then updated with those key:value pairs.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ dictionaries โ€บ .update()
Python | Dictionaries | .update() | Codecademy
May 13, 2025 - Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today. ... other: This can be a dictionary or an iterable of key-value pairs (like a list of tuples). If there is a duplicate key in dict and other, the key-value pair in dict is replaced with the key-value pair in other. ... The .update() method updates the dictionary in place and returns None. This example uses the .update() method to add the entries from one dictionary to another:
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-dictionary-update
Python Dictionary Update
January 12, 2026 - # Initial Python dictionary containing ... update new_hubs = { "Massachusetts": "Boston", "New York": "NYC", "Texas": "Austin (Silicon Hills)" # This will update the existing value } # Performing the Python dictionary update tech_hubs.update(new_hubs) # Displaying the updated Python dictionary print(tech_hubs) You can see the output in the screenshot below. In the example above, I updated the entry for Texas and added Massachusetts and New York in one go...
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ how to update a python dictionary?
How to Update a Python Dictionary? - AskPython
August 6, 2022 - dict = {"Python":100,"Java":150} print("Dictionary before updation:",dict) dict.update(C = 35,Fortran = 40) print("Dictionary after updation:",dict) In the above example, we have updated the input dict with the values passed to the update() function.
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-update-dictionary
Python Update Dictionary: Methods and Usage Guide
January 30, 2024 - In this example, we have two dictionaries: original_dict and update_dict. We use dictionary comprehension to merge these two dictionaries into new_dict. The values from update_dict overwrite the values from original_dict for any common keys.
๐ŸŒ
Oreate AI
oreateai.com โ€บ blog โ€บ using-the-python-dictionary-update-method โ€บ 0c2a1bcf87689d70361351213c5e7967
Using the Python Dictionary Update Method - Oreate AI Blog
December 22, 2025 - Purpose of the Update Method The primary purposes are: To modify existing entries within a dictionary: If both dictionaries share common keys, values from dict2 replace those in dict. To merge two dictionaries: New entries from dict2 are added into dict when there are no matching keys present between them. Examples Using Update Method Below are some examples demonstrating how to use update for updating or merging dictionaries: 5.1 Updating with another dictionary object as parameter
๐ŸŒ
Python Central
pythoncentral.io โ€บ python-dictionary-update-method-how-to-add-change-or-modify-values
Python Dictionary Update() Method: How To Add, Change, Or Modify Values | Python Central
January 29, 2024 - Writing this example in Python using dictionaries would look something like this: Now, to add the new books you've purchased to the current library, you can use the update() function.
Top answer
1 of 2
53

The difference is that the second method does not work:

>>> {}.update(1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: update expected at most 1 arguments, got 2

dict.update() expects to find a iterable of key-value pairs, keyword arguments, or another dictionary:

Update the dictionary with the key/value pairs from other, overwriting existing keys. Return None.

update() accepts either another dictionary object or an iterable of key/value pairs (as tuples or other iterables of length two). If keyword arguments are specified, the dictionary is then updated with those key/value pairs: d.update(red=1, blue=2).

map() is a built-in method that produces a sequence by applying the elements of the second (and subsequent) arguments to the first argument, which must be a callable. Unless your key object is a callable and the value object is a sequence, your first method will fail too.

Demo of a working map() application:

>>> def key(v):
...     return (v, v)
... 
>>> value = range(3)
>>> map(key, value)
[(0, 0), (1, 1), (2, 2)]
>>> product = {}
>>> product.update(map(key, value))
>>> product
{0: 0, 1: 1, 2: 2}

Here map() just produces key-value pairs, which satisfies the dict.update() expectations.

2 of 2
5
  • Python 3.9 and PEP 584 introduces the dict union, for updating one dict from another dict.
    • Dict union will return a new dict consisting of the left operand merged with the right operand, each of which must be a dict (or an instance of a dict subclass). If a key appears in both operands, the last-seen value (i.e. that from the right-hand operand) wins.
  • See SO: How do I merge two dictionaries in a single expression? for merging with the new augmented assignment version.
    • This answer.
>>> d = {'spam': 1, 'eggs': 2, 'cheese': 3}
>>> e = {'cheese': 'cheddar', 'aardvark': 'Ethel'}
>>> d | e
{'spam': 1, 'eggs': 2, 'cheese': 'cheddar', 'aardvark': 'Ethel'}
>>> e | d
{'aardvark': 'Ethel', 'spam': 1, 'eggs': 2, 'cheese': 3}
  • Additional examples from the PEP.

Motivation

The current ways to merge two dicts have several disadvantages:

dict.update

d1.update(d2) modifies d1 in-place. e = d1.copy(); e.update(d2) is not an expression and needs a temporary variable.

{**d1, **d2}

Dict unpacking looks ugly and is not easily discoverable. Few people would be able to guess what it means the first time they see it, or think of it as the "obvious way" to merge two dicts.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-update-dictionary-with-other-dictionary
Update Dictionary with other Dictionary - Python - GeeksforGeeks
July 12, 2025 - For example, consider two dictionaries, a = {'gfg': 1, 'best': 2, 'for': 4, 'geeks': 6} and b = {'for': 3, 'geeks': 5}. When we update a with b, the values of the common keys ('for' and 'geeks') in a are replaced with the corresponding values ...