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

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

In your case:

book_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....
Discussions

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
When updating a dictionary using a for loop, all keys return the same value (despite iterating through multiple values.)
Asher Orr is having issues with: Hi everyone! I created a function called splitsville. It takes 1 parameter, an address ('100 E Main St, Anywhereville, Oregon, 22222'.) More on teamtreehouse.com
🌐 teamtreehouse.com
1
June 24, 2022
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
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
🌐
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].
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-add-to-dictionary
How to Add and Update Python Dictionaries Easily | DigitalOcean
October 16, 2025 - Outputoriginal dictionary: {'Website': ... Add to a Python Dictionary', 'Author': 'Sammy Shark', 'Guest1': 'Dino Sammy', 'Guest2': 'Xray Sammy'} The output shows that the first update adds a new key-value pair and the second update adds the key-value pairs from the guest dictionary to the site dictionary. Note that if your update to a dictionary includes an existing key, then the old value is overwritten by the ...
🌐
Team Treehouse
teamtreehouse.com › community › when-updating-a-dictionary-using-a-for-loop-all-keys-return-the-same-value-despite-iterating-through-multiple-values
When updating a dictionary using a for loop, all keys return the same value (despite iterating through multiple values.) (Example) | Treehouse Community
June 24, 2022 - Now, I'm trying to return a dictionary with the keys: ... ... and the corresponding values from the split string. For example: {'street': '100 E Main St', 'city': 'Anywhereville', etc.} ... def splitsville(address): address_values = address.split(", ") dictionary = {} for value in address_values: dictionary.update({"street" : value}) dictionary.update({"city" : value}) dictionary.update({"state" : value}) dictionary.update({"zip_code" : value}) print(dictionary) splitsville("100 E Main Street, Anywhereville, Oregon, 22222")
🌐
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.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › can a dictionary automatically update another dictionary with a shared key?
r/learnpython on Reddit: Can a dictionary automatically update another dictionary with a shared key?
January 9, 2022 -

I'll give more context about the specific problem down below but first to make it simple:

I have 2 dictionaries that share 1 key. The program is going to take an input from the user, compare it to a list of possible inputs, and change the value of that shared key depending on what input was given.

The way its written now, the input only changes the value on one dictionary, not both. So how do I make it so changing the value of a key on one dictionary makes it pass the new value onto every other dictionary that uses the same key?

For example:

dic_1 = {'a': 7, 'b': 19, 'c': ' '}

dic_2 = {'c': ' ', 'd': 34, 'e': 35}

some_list = [pretend this is a list of values]

def some_function():

    var = input()

    if var in some_list:

        dic_1['c'] = 17

To sum it up, the user inputs a value that is referenced to a list, and depending on what value in the list was input, the value of key['c'] is changed in dic_1.

How do I make this change also automatically change the value of dic_2, and any other dictionary that also shares the key['c']?

Am I going to have to manually include it in some_function()? Or how would the best way to do it?

Tl;Dr 

Multiple dictionaries share the same key. How do I make it so changing the value of that key in one dictionary also changes the value of the key in every dictionary?

I'm probably way over-engineering this but hey I'm a really rusty and learning it all again after over a year of not touching a single programming language

🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › how-to-update-a-python-dictionary-values
How to update a Python dictionary values?
June 9, 2025 - Here is the syntax of updating the values of a dictionary using either the method - dictionary[key] = new_value dictionary.update({key: new_value}) We can update a specific value in a Python dictionary by referencing the key and assigning it a new value using the assignment operator "=".
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-dictionary-update-method
Python Dictionary update() method - GeeksforGeeks
2 weeks ago - Explanation: update({'a': 50}) replaces old value of 'a'. Example 3: In this example, keyword arguments are used instead of another dictionary.
🌐
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

🌐
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.
🌐
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....
🌐
UiPath Community
forum.uipath.com › help
Update Dictionary Value if Key exists - Help - UiPath Community Forum
February 25, 2019 - So I have this Dictionary 3.00 And I come across another apple row, I’m checking to see if that key exists, if it ...
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.3 documentation
The main operations on a dictionary are storing a value with some key and extracting the value given the key. It is also possible to delete a key:value pair with del. If you store using a key that is already in use, the old value associated with that key is forgotten. Extracting a value for a non-existent key by ...
🌐
Reddit
reddit.com › r/learnpython › how to change a dicts value for one of the keys?
r/learnpython on Reddit: How to change a dicts value for one of the keys?
February 5, 2024 -

I have been trying to do this singular issue for a couple hours. I basically want to get the value of one key in my dict and add to it, but not to any of the other keys. I have searched all over the internet and can not find or just do not know how to word it to find a solution. This is what I have soo far, which creates the dictionary with user inputs and assigns 1 to all their values. Any help would save my mental state.

EDIT: wow extremely helpful community here. I'm actually really impressed. Will take all the info here and apply it. Saved me hours of frustration.

list = {}

while True:
    try:
        item = input()
        value = 1
        list[item] = value
        sorted_list = dict(sorted(list.items()))

    except EOFError:
        break


for item in sorted_list:
    print(str(value) + " " + item.upper())
Top answer
1 of 7
14
list = {} Triggered. Sorry, mostly kidding, but list is a type, and definitely should not be used as the variable name for a dict. Also, using a try/except on EOFError for breaking out of your while loop is really weird. Are you trying to mess with people? =) Again, kidding, lol. I basically want to get the value of one key in my dict and add to it, but not to any of the other keys. I have searched all over the internet and can not find or just do not know how to word it to find a solution. What are you actually expecting to do? As written, your code doesn't attempt to change any value, and doing so is very simple. Let's say one of your inputs is "apple". This creates the following key/value pair in your dict: {"apple": 1}. To change this value to, say, 5, you'd simply do this: my_dict["apple"] = 5 That changes the value from 1 to 5. Now, if you want to add to it in the sense of a number, you can do this instead: my_dict["apple"] += 5 This will add 5 to the original value of 1, so your new dict will be this: {"apple": 1} Finally, if you mean "add" as in "add additional values", you need to convert your value into a type that allows for multiple values. The most common is to use a list like this: my_dict = {} dict_key = input() my_dict[dict_key] = [1] my_dict[dict_key].append(5) print(my_dict) # input: test # output: {'test': [1, 5]} If you gave some more details about what you are trying to do we can probably help more. Does that make sense?
2 of 7
8
my_dict = { 'key' : 'value'} print(my_dict) my_dict['key'] = 'new_value' print(my_dict) You change a dictionary keys value by assigning it again
🌐
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.
🌐
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)