A benchmark shows your suspicions of its performance impact appear to be correct:

$ python -m timeit -s 'd = {"key": "value"}' 'd["key"] = "value"'
10000000 loops, best of 3: 0.0741 usec per loop
$ python -m timeit -s 'd = {"key": "value"}' 'd.update(key="value")'
1000000 loops, best of 3: 0.294 usec per loop
$ python -m timeit -s 'd = {"key": "value"}' 'd.update({"key": "value"})'
1000000 loops, best of 3: 0.461 usec per loop

That is, it's about six times slower on my machine. However, Python is already not a language you'd use if you need top performance, so I'd just recommend use of whatever is most readable in the situation. For many things, that would be the [] way, though update could be more readable in a situation like this:

configuration.update(
    timeout=60,
    host='example.com',
)

…or something like that.

Answer from icktoofay on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-add-to-dictionary
How to Add and Update Python Dictionaries Easily | DigitalOcean
October 16, 2025 - Assignment operator (=): Best for single item updates and offers the fastest performance · update() method: Most efficient for bulk operations and merging multiple dictionaries · Merge operator (|): Creates new dictionaries without modifying originals (Python 3.9+)
🌐
Reddit
reddit.com › r/cs50 › dictionary update method replaces instead of updating
r/cs50 on Reddit: Dictionary Update Method Replaces Instead of Updating
April 8, 2022 -

I've completed DNA and submitted for full credit using lists instead of dictionaries. DNA was really enthralling to me for some reason and I'm going back and trying to make my code both more pythonic and attempting to get it better optimized. Part of my motivation is that I just don't feel anywhere near as comfortable with dictionaries as I did coming out of previous weeks' psets that had similar, heavier (for me) concepts.

One specific area that's giving me trouble in my understanding is the .update() method. I'm using it to store the small.csv info into a dict named STR. I had thought it was the analogue of .append() for lists but, after trying to incorporate it into my revamped DNA, it will update for the first row of the CSV being read on the first iteration but then it just continually replaces that single row/entry in the dict with each iteration. I'm sure I'm just not grasping something fundamental about dicts and/or update() but am not knowledgeable enough yet to know what that might be. I'm not even sure it's technically necessary to be storing the database csv or if it's better to work with the CSV in-place.

Could someone please help me understand why my expectation of update() is flawed?

The code below only stores the last line of the small.csv database:

{'name': 'Charlie', 'AGATC': '3', 'AATG': '2', 'TATC': '5'}

    # Open person STR profiles csv and append to STR list

    with open(sys.argv[1], 'r', newline = '') as file:
        reader = csv.DictReader(file)
        for row in reader:
            STR.update(row)
🌐
YouTube
youtube.com › watch
python dict update vs assign - YouTube
Download this code from https://codegive.com Dictionaries in Python are versatile data structures that allow you to store and manipulate key-value pairs. Two...
Published   January 21, 2024
🌐
Python Guides
pythonguides.com › python-dictionary-update
Python Dictionary Update
January 12, 2026 - To wrap things up, here is a quick look at when to use each Python dictionary update method: .update(): Use this for standard, in-place bulk updates. Direct Assignment: Best for updating or adding a single key-value pair.
🌐
TestMu AI Community
community.testmu.ai › ask a question
Why would I use `dict.update()` in Python instead of assigning values directly? - TestMu AI Community
November 11, 2025 - I understand that the update() method on dictionaries in Python can be used to add new key-value pairs or update existing ones. For example: my_dict = {'1': 11, '2': 1445} my_dict.update({'1': 645, 5: 123}) This will result in: {'1': 645, '2': 1445, 5: 123} But I can also achieve the same effect by directly assigning values: my_dict['1'] = 645 my_dict[5] = 123 This also gives: {'1': 645, '2': 1445, 5: 123} So I’m wondering, in what situations is python dict update crucial or more benefic...
Find elsewhere
🌐
Python
peps.python.org › pep-0584
PEP 584 – Add Union Operators To dict | peps.python.org
Update a dict in place: The Obvious Way is to use the update() method. If this proposal is accepted, the |= augmented assignment operator will also work, but that is a side-effect of how augmented assignments are defined.
🌐
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 - In this tutorial, we’ll look at how you can add or update items in a dictionary. Before we proceed, here’s a quick refresher on dictionaries in python – Dictionaries are a collection of items used for storing key to value mappings. They are mutable and hence we can update the dictionary by adding new key-value pairs, removing existing key-value pairs, or changing the value corresponding to a key.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-dictionary-update-method
Python Dictionary update() method - GeeksforGeeks
October 22, 2018 - update() method in Python dictionary is used to add new key-value pairs or modify existing ones using another dictionary, iterable of pairs or keyword arguments. If a key already exists, its value is replaced.
🌐
Reddit
reddit.com › r/learnpython › python dictionary update - is this right approach?
r/learnpython on Reddit: Python Dictionary update - is this right approach?
July 3, 2024 -

Hallo Team,

I want to update a json file which no less than 100 values.

Here is short example, I wish to update the values in this json file

{
    "skipEsxThumbprintValidation": true,
    "managementPoolName": "pool-md-vcf0-ko",
    "sddcManagerSpec": {
        "hostname": "sddc-md-vcf0-ko",
        "ipAddress": "172.16.18.59",
        "netmask": "255.255.255.0",
        "localUserPassword": "YouknowBetter!",
        "rootUserCredentials": {
            "username": "root",
            "password": "YouknowBetter!"
        },
        "secondUserCredentials": {
            "username": "vcf",
            "password": "YouknowBetter!"
        }
    },

my code looks like below

# Purpose: read the json template and create a new bringup file out of it
import json

bringup_template = "vcf51_bring_template.json"
with open(bringup_template, "r") as f:
    template_data = json.load(f)
sddcspecs = template_data.get("sddcManagerSpec")

sddcspecs["hostname"] = "test"
sddcspecs["ipAddress"] = "someip"
sddcspecs["netmask"] = "somedata"
sddcspecs["localUserPassword"] = "something"
sddcspecs["rootUserCredentials"] = "something"
sddcspecs["secondUserCredentials"] = "something"
template_data.update(sddcspecs)
print(template_data)

I was wondering if there is better approach to update this dictionary. The above is a very small snippet of json file. I have minimum 100 values to update. I see this is literally typing all things without much logic.

Is there a better approach?

🌐
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.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Add and Update an Item in a Dictionary in Python | note.nkmk.me
August 25, 2023 - In this case, keys must be valid identifiers in Python. They cannot start with a number or contain symbols other than _. ... # d.update(k-3=3) # SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
🌐
Quora
quora.com › How-do-I-update-key-and-value-in-dictionary-in-python
How to update key and value in dictionary in python - Quora
Use direct assignment or update for simple value changes. Use pop+assign or construct a new dict when renaming keys. Use comprehensions for bulk or conditional transforms. Examples above work in CPython and reflect Python semantics as of May 2024.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-update-dictionary-with-other-dictionary
Update Dictionary with other Dictionary - Python - GeeksforGeeks
July 12, 2025 - However, it can also be used to update existing keys in the dictionary by directly assigning values from another dictionary. While it's efficient, this method is less commonly used for updating values since it's primarily designed for inserting default values for missing keys. Python ·
🌐
Hostbillo
hostbillo.com › blog › how-to-add-and-update-items-to-a-dictionary-in-python
How to Add and Update Items to a Dictionary in Python?
Whether initializing an empty ... and manageable. ... The update() method is a robust and efficient way to manipulate Python dictionaries, specifically when dealing with multiple items....
🌐
Python Forum
python-forum.io › thread-12912.html
assign a value to a dict change all the values
hello, i am really getting mad with these few lines of code from random import randint header = ['test', '1', '2', '12', 'GG', 'NG'] lis = ['alpha', 'beta', 'gamma'] list_p = list() dict_p = dict.fromkeys(header) def random(): for item in l...
🌐
Programiz
programiz.com › python-programming › methods › dictionary › update
Python Dictionary update()
The update() method takes either a dictionary or an iterable object of key/value pairs (generally tuples). If update() is called without passing parameters, the dictionary remains unchanged.
🌐
Educative
educative.io › answers › how-to-update-and-remove-elements-from-a-python-dictionary
How to update and remove elements from a Python dictionary
Python allows a dictionary object to be mutable, meaning update or add operations are permissible. A new item can be pushed or an existing item can be modified with the aid of an assignment operator.