Well you could directly substract from the value by just referencing the key. Which in my opinion is simpler.

Copy>>> books = {}
>>> books['book'] = 3       
>>> books['book'] -= 1   
>>> books   
{'book': 2}   

In your case:

Copybook_shop[ch1] -= 1
Answer from Christian W. on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_dictionaries_change.asp
Python - Change Dictionary Items
Python Examples Python Compiler ... } thisdict["year"] = 2018 Try it Yourself » · The update() method will update the dictionary with the items from the given argument....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-update-dictionary-value-by-key
Python Update Dictionary Value by Key - GeeksforGeeks
July 23, 2025 - Note: In case, since the key 'grade' already exists, setdefault() does not update its value to 'A'. Instead, it leaves the value as 'B'. So, If you want to update the value of a key regardless of whether it exists or not, you should directly assign the new value to the key as shown above example 1 [Update Dictionary by Key Using The Square Brackets].
Discussions

Update values in a dictionary, from a list, if the value is currently 1
my_dict = {'date1':0, 'date2':1, 'date3':0, 'date4':1} my_list = [80, 20] list_index = 0 new_dict = {} for key in my_dict: value = my_dict[key] if value == 1: new_dict[key] = my_list[list_index] list_index += 1 else: new_dict[key] = my_dict[key] print(new_dict) More on reddit.com
🌐 r/learnpython
5
0
October 28, 2022
Here's a quick way to update a dictionary with a second dictionary: use the '|=' operator.
This is cool and nice to know about, but frankly DictA.update(DictB) is better IMHO. The result is exactly the same, but it’s more readable / less opaque and arcane. Even Pythonistas who have never heard of dict.update can probably guess what it does, unlike |= which you already have to be in-the-know about. dict.update is probably more backwards compatible too, though I’m less certain about this. More on reddit.com
🌐 r/learnpython
12
54
May 27, 2023
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
Can a dictionary automatically update another dictionary with a shared key?
You create class and store value as a class member. Make one Instance if the class the value of both dicts with the same key. If you change value inside class instance it will be seen in both dicts. You may need to think about getter/setter of the class to make code look similar to regular value assignments More on reddit.com
🌐 r/learnpython
8
2
January 9, 2022
🌐
Codecademy
codecademy.com › docs › python › dictionaries › .update()
Python | Dictionaries | .update() | Codecademy
May 13, 2025 - Updates the dictionary with key-value pairs from another dictionary or iterable, overwriting existing keys if they exist.
🌐
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.
🌐
InterServer
interserver.net › home › python › learn how to modify python dictionary values easily
Learn How to Modify Python Dictionary Values Easily - Interserver Tips
February 3, 2026 - The simplest way to change a dictionary value is by using direct assignment. The syntax is straightforward: ... If the key already exists, its value will be replaced with the new one. This makes it easy to update data quickly without using extra functions. ... Here, the key “marks” already ...
🌐
Reddit
reddit.com › r/learnpython › update values in a dictionary, from a list, if the value is currently 1
r/learnpython on Reddit: Update values in a dictionary, from a list, if the value is currently 1
October 28, 2022 -

Say I have code like so:

my_dict = {date1:0, date2:1, date3:0, date4:1} my_list = [80, 20]

Is there a way to get output as follows:

new_dict = {date1:0, date2:80, date3:0 date4:20}

I've tried so much at this point but just cannot get it working, is my initial structure the issue? i.e. you're not supposed to use dictionaries like this? Either you can't do this, or there's a fundamental gap in my knowledge preventing me connecting the dots. Or I'm dumb!

TIA

Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-dictionary-update-method
Python Dictionary update() method - GeeksforGeeks
February 16, 2026 - Explanation: update({'a': 50}) replaces old value of 'a'. Example 3: In this example, keyword arguments are used instead of another dictionary.
🌐
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
EDIT: This is called “inverting” a dictionary. You can do it by iterating through the dict, using .items() to extract each key/value pair and making the value the key, and vice versa: >>> name_to_num = { 'Bruce Lee': 36564, 'Bob Ross': 37381, 'Mary Barra': 98927 } ... You may recognize the pattern above, namely–creating an empty container and then filling it via a loop, as being the exact situation in which one should use a comprehension in Python.
🌐
Tutorialspoint
tutorialspoint.com › python › dictionary_update.htm
Python dictionary update() Method
When a method is invoked, the keyword(name) of the argument is used to assign value to it. # creating a dictionary dict_1 = {'Animal': 'Lion'} res = dict_1.update(Order = 'Carnivora', Kingdom = 'Animalia') print(dict_1)
🌐
W3Schools
w3schools.com › python › gloss_python_change_dictionary_item.asp
Python Change Values in a Dictionary
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
🌐
W3Schools
w3schools.com › python › ref_dictionary_update.asp
Python Dictionary update() Method
Python Examples Python Compiler ... car.update({"color": "White"}) print(car) Try it Yourself » · The update() method inserts the specified items to the dictionary....
🌐
AskPython
askpython.com › home › how to update a python dictionary?
How to Update a Python Dictionary? - AskPython
August 6, 2022 - The function does not return any values, rater it updates the same input dictionary with the newly associated values of the keys. ... dict = {"Python":100,"Java":150} up_dict = {"Python":500} print("Dictionary before updation:",dict) dict.update(up_dict) print("Dictionary after updation:",dict)
🌐
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 30, 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.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Add and Update an Item in a Dictionary in Python | note.nkmk.me
August 25, 2023 - Built-in Types - dict.update() — Python 3.11.3 documentation · If the keyword argument (key=value) is specified for update(), the item with that key and value is added.
🌐
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. By Bala Priya C, KDnuggets Contributing Editor & Technical Content Specialist on February 20, 2023 in Python
🌐
iO Flood
ioflood.com › blog › python-update-dictionary
Python Update Dictionary: Methods and Usage Guide
January 30, 2024 - The ** operator unpacks the dictionaries and overwrites the values of original_dict with the values of update_dict for any common keys. These advanced techniques provide more flexibility and control when updating dictionaries in Python. However, they also require a deeper understanding of Python’s syntax and concepts.
🌐
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 › check-and-update-existing-key-in-python-dictionary
Check and Update Existing Key in Python Dictionary - GeeksforGeeks
July 23, 2025 - If the key is found, its value can be updated to a new value, if the key is not found, an alternative action can be taken, such as adding a new key-value pair or leaving the dictionary unchanged. 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.