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.

Answer from Paolo Bergantino on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dictionaries_add.asp
Python - Add Dictionary Items
Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else
Discussions

How do you add to a value in a dictionary?
new_dict[word] += 1 This presumes it already has a value, and as written, will be the case. More on reddit.com
๐ŸŒ r/learnpython
13
1
October 14, 2021
Okay so apparently in python you can't add dictionaries into sets but you can update dictionaries into sets which makes 0 sense to me please someone explain
You cannot "update dictionaries into sets". You can create a set from either the keys, or the values, from a dictionary. >>> D = {"a": 1, "b": 2, "c": 3} >>> S = set(D) >>> S {'c', 'b', 'a'} As for why you cannot add dictionaries into sets, it is because they are unhashable . >>> S.add(D) Traceback (most recent call last): File "", line 1, in TypeError: unhashable type: 'dict' More on reddit.com
๐ŸŒ r/learnprogramming
18
2
June 24, 2022
How to append to dictionary within a for loop
# Adding the entry {'Team_A' : 10} to a dict my_dict = {} my_dict['Team_A'] = 10 # Retrieving the value from a dict team_a_score = my_dict['Team_A'] print(team_a_score) # prints 10 ---------------------------------- He's a simplified version of what you currently have names_list = ['person_A', 'person_B', 'person_C'] d = {} for name in names_list: d[name].append(10) The piece d[name] on the last line is how you would retrieve a value from a dictionary. It tries to retrieve the first name in the list, person_A, from the dictionary and throws a KeyError because that key doesn't exist. Did you mean to instead add a value to the dictionary? You would use the assignment operator, = # assigns the value 10 to eat name key names_list = ['person_A', 'person_B', 'person_C'] d = {} for name in names_list: d[name] = 10 More on reddit.com
๐ŸŒ r/learnpython
5
3
July 24, 2022
What is the fastest way to iterate over a dictionary?
try again but this time do "for key, vals in dictName.items()" first and "for vals in dictName.values():" second see if your times still hold More on reddit.com
๐ŸŒ r/learnpython
17
99
January 4, 2023
Top answer
1 of 16
4462

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
1365

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))
๐ŸŒ
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 - Dictionaries are widely used in Python for various applications such as counting occurrences, grouping data, and storing configurations. Despite their versatility, thereโ€™s no built-in add method for dictionaries.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-dictionary-append
Python Dictionary Append: How to Add Key-Value Pairs | DataCamp
August 6, 2024 - In this example, we start with dictionary_w_list where the key 'fruits' maps to a list ['apple', 'banana']. By using the .append() method, we add 'cherry' to the list. This technique is particularly useful when managing collections of items within a single dictionary. Python 3.9 introduced the merge operator (|) for combining dictionaries.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-add-dictionary-items
Python - Add Dictionary Items - GeeksforGeeks
July 23, 2025 - If you want to add multiple items at once or update existing items, update() method is the most efficient way. This method accepts another dictionary or an iterable of key-value pairs and adds those pairs to the original dictionary.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_ref_dictionary.asp
Python Dictionary Methods
Python has a set of built-in methods that you can use on dictionaries. Learn more about dictionaries in our Python Dictionaries Tutorial.
๐ŸŒ
PhoenixNAP
phoenixnap.com โ€บ home โ€บ kb โ€บ devops and development โ€บ python: how to add items to dictionary
Python: How to Add Items to Dictionary
December 19, 2025 - The code shows the updated dictionary contents after adding a new item. The update() method adds a new element to an existing dictionary:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-dictionary
Python Dictionary - GeeksforGeeks
d = {1: 'Geeks', 2: 'For', 3: 'Geeks'} # Adding a new key-value pair d["age"] = 22 # Updating an existing value d[1] = "Python dict" print(d) Output ยท {1: 'Python dict', 2: 'For', 3: 'Geeks', 'age': 22} Dictionary items can be removed using built-in deletion methods that work on keys: del: removes an item using its key ยท
Published ย  2 weeks ago
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_dictionary_add_item.asp
Python Adding Items in a Dictionary
Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else
๐ŸŒ
SitePoint
sitepoint.com โ€บ python hub โ€บ adding items to dictionaries
Python - Adding Items to Dictionaries | SitePoint โ€” SitePoint
It follows the same pattern as other Python operators like += for numbers. Just as number += 5 adds 5 to your number, capitals |= new_capitals adds new items to your dictionary. One thing to note: just like with other methods, if there are any matching keys, the new values will replace the old ones:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-add-new-keys-to-a-dictionary
Add new keys to a dictionary in Python - GeeksforGeeks
July 11, 2025 - The update() method can be use to merge dictionaries or add multiple keys and their values in one operation.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-add-items-to-dictionary
Python - Add Items to Dictionary - GeeksforGeeks
July 23, 2025 - It adds the new items to the dictionary or updates the values of existing keys. setdefault() method adds an item to the dictionary only if the key does not already exist.
๐ŸŒ
Guru99
guru99.com โ€บ home โ€บ python โ€บ python dictionary append: how to add key/value pair
Python Dictionary Append: How to Add Key/Value Pair
August 13, 2025 - The keys in the dictionary are Name, Address and Age. Usingappend() methodwe canupdate the values for the keys in the dictionary.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_add_dictionary_items.htm
Python - Add Dictionary Items
It is part of the collections module in Python's standard library. We can add dictionary items using the collections.defaultdict() method by specifying a default factory, which determines the default value for keys that have not been set yet.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ add-to-dict-in-python
Adding to Dict in Python โ€“ How to Append to a Dictionary
February 28, 2023 - Example using the update() method to add multiple entries to a dictionary: myDict = {'a': 1, 'b': 2} new_data = {'c': 3, 'd': 4} myDict.update(new_data) print(myDict) ... Another fun thing about this method is that, we can use the update() method with an iterable of key-value pairs, such as a list of tuples. Let's see this in action. myDict = {'a': 1, 'b': 2} new_data = [('c', 3), ('d', 4)] myDict.update(new_data) print(myDict) ... In Python, a dictionary can be updated or made from scratch using the dict() constructor...
๐ŸŒ
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.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ append-a-value-to-a-dictionary-python
Append a Value to a Dictionary Python - GeeksforGeeks
July 23, 2025 - Explanation: update() adds key-value pairs from another dictionary to the existing dictionary d. If a key already exists, its value is updated otherwise, the key-value pair is added.
๐ŸŒ
Cisco
ipcisco.com โ€บ home โ€บ python add to dictionary
Python Add To Dictionary | update() method | append() method โ‹†
March 5, 2026 - In this lesson, we will learn How to add a member to Python Dictionary. We will do different coding examples like Python dictionary add and python dictionary append. We can use these methods to insert a new item.