You can do

orig.update(extra)

or, if you don't want orig to be modified, make a copy first:

dest = dict(orig)  # or orig.copy()
dest.update(extra)

Note that if extra and orig have overlapping keys, the final value will be taken from extra. For example,

>>> d1 = {1: 1, 2: 2}
>>> d2 = {2: 'ha!', 3: 3}
>>> d1.update(d2)
>>> d1
{1: 1, 2: 'ha!', 3: 3}
Answer from mipadi on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dictionaries_add.asp
Python - Add Dictionary Items
Python Overview Python Built-in ... Python Dictionary Methods Python Tuple Methods Python Set Methods Python File Methods Python Keywords Python Exceptions Python Glossary ยท Built-in Modules Random Module Requests Module Statistics Module Math Module cMath Module ยท Remove List Duplicates Reverse a String Add Two Numbers ยท Python Examples Python Compiler ...
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ python-dictionary-append-how-to-add-items-to-dictionary
Python Dictionary Append: How to Add Items to Dictionary | Codecademy
The most direct and commonly used way to add or update items in a Python dictionary is by using square brackets ([]) with the assignment operator (=). This method allows you to assign a value to a new key or update the value of an existing 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 = {'Guest1':'Dino Sammy', 'Guest2':'Xray Sammy'}
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-dictionary-append
Python Dictionary Append: How to Add Key-Value Pairs | DataCamp
August 6, 2024 - Hereโ€™s a more detailed example to illustrate the structure: # A more complex dictionary employee = { 'id': 101, 'name': 'John Doe', 'age': 30, 'department': 'Engineering', 'skills': ['Python', 'Machine Learning', 'Data Analysis'], 'address': { 'street': '123 Main St', 'city': 'San Francisco', 'state': 'CA', 'zip': '94105' } } # Accessing nested data print(employee['skills'][1]) # Output: Machine Learning print(employee['address']['city']) # Output: San Francisco
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how do you add to a value in a dictionary?
r/learnpython on Reddit: How do you add to a value in a dictionary?
October 14, 2021 -

I know how to update values in a dictionary. That's easy, and there are multiple ways to do it. However, what I'm looking for is how to add to a value in a dictionary. For example:

    def frequency_dictionary(words):
      new_dict = {}
      for word in words:
        if word not in new_dict:
          new_dict[word] = 1
        else:
           #?????
      return new_dict

I want this function to add 1 to the value of a word for each time it is featured in the words list. For example, print(frequency_dictionary(["apple", "apple", "cat", 1])) should return {"apple":2, "cat":1, 1:1}. The comment in the function with question marks is the part I am stuck on. What are some options to do this?

I tried looking this up, but all I got was info on how to update values, not add to them.

๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ add-to-dict-in-python
Adding to Dict in Python โ€“ How to Append to a Dictionary
February 28, 2023 - Here is an illustration of a basic dictionary: my_dict = {"pineapple": 12, "apple": 30, "orange": 5, "avocado":7} In this example, "pineapple", "apple", "orange", and "avocado" are the keys, and 12, 30, 5 and 7 are the corresponding values.
๐ŸŒ
PhoenixNAP
phoenixnap.com โ€บ home โ€บ kb โ€บ devops and development โ€บ python: how to add items to dictionary
Python: How to Add Items to Dictionary
December 22, 2025 - Learn how to add items to a Python dictionary in this guide through example code. See how you can add multiple items at once through loops.
Find elsewhere
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ add-values-to-dictionary-python
How To Add Values To A Dictionary In Python - Flexiple
To add values to a dictionary in Python, one effective method is using the in-place merge (|=) operator. This operator was introduced in Python 3.9 and provides a convenient way to merge two dictionaries.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ append python dictionary to dictionary
Append Python Dictionary to Dictionary - Spark By {Examples}
May 31, 2024 - To append a dictionary to a list of dictionaries in Python, you can use the append() method of the list. For example, the append() method is used to add the dictionary new_dict to the end of the list list_of_dicts.
๐ŸŒ
Career Karma
careerkarma.com โ€บ blog โ€บ python โ€บ python add to dictionary: a guide
Python Add to Dictionary: A Guide | Career Karma
December 1, 2023 - Instead, you add an item to a dictionary by inserting a new index key into the dictionary, then assigning it a particular value. This tutorial discussed, with an example, how to add an item to a Python dictionary.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-dictionary
Python Dictionary
The arrows show how each key is connected to its corresponding value. ... Dictionary Creation Programs. Dictionary Add/Append Programs.
Published ย  January 25, 2018
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-nested-dictionary
Python Nested Dictionary - GeeksforGeeks
July 12, 2025 - Letโ€™s look at how to create, add to, access and delete data in nested dictionaries. Creating a Nested Dictionary means placing dictionaries as values inside an outer dictionary using curly braces {}. ... This example creates a nested dictionary to store details of multiple students.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ add dictionary to a dictionary python
How to Add Dictionary to Dictionary in Python | Delft Stack
February 2, 2024 - There are 4 main methods that can be used to add a dictionary to another dictionary in Python; the update() method, the dictionary unpacking operator, the dictionary union operator, and the ChainMap class inside the collections module.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ home โ€บ python โ€บ add items to dictionary in python
Add Items to Dictionary in Python
February 21, 2009 - We can add dictionary items using the setdefault() method by specifying a key and a default value. In this example, we use the setdefault() to add the key-value pair "major": "Computer Science" to the "student" dictionary โˆ’
Top answer
1 of 16
4456

You create a new key/value pair on a dictionary by assigning a value to that key

d = {'key': 'value'}
print(d)  # {'key': 'value'}

d['mynewkey'] = 'mynewvalue'

print(d)  # {'key': 'value', 'mynewkey': 'mynewvalue'}

If the key doesn't exist, it's added and points to that value. If it exists, the current value it points to is overwritten.

2 of 16
1364

I feel like consolidating info about Python dictionaries:

Creating an empty dictionary

data = {}
# OR
data = dict()

Creating a dictionary with initial values

data = {'a': 1, 'b': 2, 'c': 3}
# OR
data = dict(a=1, b=2, c=3)
# OR
data = {k: v for k, v in (('a', 1), ('b',2), ('c',3))}

Inserting/Updating a single value

data['a'] = 1  # Updates if 'a' exists, else adds 'a'
# OR
data.update({'a': 1})
# OR
data.update(dict(a=1))
# OR
data.update(a=1)

Inserting/Updating multiple values

data.update({'c':3,'d':4})  # Updates 'c' and adds 'd'

Python 3.9+:

The update operator |= now works for dictionaries:

data |= {'c':3,'d':4}

Creating a merged dictionary without modifying originals

data3 = {}
data3.update(data)  # Modifies data3, not data
data3.update(data2)  # Modifies data3, not data2

Python 3.5+:

This uses a new feature called dictionary unpacking.

data = {**data1, **data2, **data3}

Python 3.9+:

The merge operator | now works for dictionaries:

data = data1 | {'c':3,'d':4}

Deleting items in dictionary

del data[key]  # Removes specific element in a dictionary
data.pop(key)  # Removes the key & returns the value
data.clear()  # Clears entire dictionary

Check if a key is already in dictionary

key in data

Iterate through pairs in a dictionary

for key in data: # Iterates just through the keys, ignoring the values
for key, value in d.items(): # Iterates through the pairs
for key in d.keys(): # Iterates just through key, ignoring the values
for value in d.values(): # Iterates just through value, ignoring the keys

Create a dictionary from two lists

data = dict(zip(list_with_keys, list_with_values))
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ adding-to-a-dict-in-python-how-to-add-to-a-dictionary
Adding to a Dict in Python โ€“ How to Add to a Dictionary
December 22, 2022 - A Python dictionary is like a JavaScript object โ€“ itโ€™s a sequence of key:value pairs. So, you can create them like this: stack_dict = { "frontend": "JavaScript", "backend": "Node JS", "markup": "HTML and JSX", } To access the value in the dictionary, you can do it this way: dict[key]. For example, if I want to access what the frontend key holds, I can do it like this: print(stack_dict["frontend"]) # JavaScript ยท But what if you want to add another entry to the dictionary without going back to the dictionary to put it there?
๐ŸŒ
TechBeamers
techbeamers.com โ€บ python-dictionary
Python Dictionary Explained with Examples - TechBeamers
November 30, 2025 - For example, the following code creates a dictionary with three keys and a default value of 0: keys = ['name', 'age', 'city'] # Create a dictionary with default value 0 dict = dict.fromkeys(keys, 0) ... There are several ways to add elements ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-add-dictionary-items
Python - Add Dictionary Items - GeeksforGeeks
July 23, 2025 - This method accepts another dictionary ... keys already exist, their values are updated. ... In this example, we added two new key-value pairs: 4: 40 and 5: 50....
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ append values to dictionary
r/learnpython on Reddit: Append values to Dictionary
June 8, 2021 -

I am currently using a while loop to loop and get certain values. I then want to append these values to a dictionary. Every loop through I want to append to two keys

General structure of the code: https://pastebin.com/p4hJcKR5

I have tried using:

dict[key] = value

dict.append(value)

And neither have worked, dict.append gives an error and dict[key] just sets the dictionary to the most recent iteration instead of iterating for all values. Any help would be appreciated.