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
๐ŸŒ
Linux Tip
linuxscrew.com โ€บ home โ€บ programming โ€บ python โ€บ how to add/append items to a dictionary in python [examples]
How to Add/Append Items to a Dictionary in Python [Examples]
November 4, 2021 - This short tutorial will show you how to add single or multiple items (as key:value pairs) to a dictionary in the Python programming language.
๐ŸŒ
Cisco
ipcisco.com โ€บ home โ€บ python add to dictionary
Python Add To Dictionary | update() method | append() method โ‹† IpCisco
December 24, 2021 - It will contain the updated member of the dictionary. In other words, it will contain new value of RU as 30. {'vendor': 'Cisco', 'model': '9000 series', 'RU': 30} Update method can get only one attribute. If you use one more attribute, it will give an error as output. To update one more key:pair, we should use differenet update lines. Letโ€™s do another example with python dictionary update method and change all the key:value pairs.
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
Append values to Dictionary
from collectioms import defaultdict d = defaultdict(list) [...] d[key].append(value) is probably what you want. You don't have to use defaultdict, you can also do sth like d = {} [...] if key in d: d[key].append(value) else: d[key] = [ value ] More on reddit.com
๐ŸŒ r/learnpython
9
2
June 8, 2021
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))
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dictionaries_change.asp
Python - Change 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
๐ŸŒ
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
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ add-to-dict-in-python
Adding to Dict in Python โ€“ How to Append to a Dictionary
February 28, 2023 - By passing a dictionary containing the new key-value pair as an argument to the dict() constructor, we can add a single key-value pair to an existing dictionary.
๐ŸŒ
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 - Use this method to add new items or to append a dictionary to an existing one. Note: Learn how to add elements to a list in Python.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-dictionary-append
Python Dictionary Append: How to Add Key-Value Pairs | DataCamp
August 6, 2024 - Learn Python dictionary append techniques such as square bracket notation, the .update() method for bulk additions, and .setdefault() for conditional inserts.
๐ŸŒ
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.

๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Add and Update an Item in a Dictionary in Python | note.nkmk.me
August 25, 2023 - You can specify another dictionary as an argument to update() to add all its items. d1 = {'k1': 1, 'k2': 2} d2 = {'k1': 100, 'k3': 3, 'k4': 4} d1.update(d2) print(d1) # {'k1': 100, 'k2': 2, 'k3': 3, 'k4': 4} ... Passing multiple dictionaries ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python add keys to dictionary
Python Add keys to Dictionary - Spark By {Examples}
May 31, 2024 - After running multiple tests on different methods to add new keys to a dictionary, the [] notation method was found to be the fastest. This is because it involves a direct reference to the dictionary and a simple assignment statement, which is a straightforward and efficient operation. import timeit my_dict = { 'Python': 1991, 'Ruby': 1995, 'Go': 2009 } # Using the [] notation t1 = timeit.timeit(stmt="my_dict['Java'] = 1995", number=1000000, globals=globals()) # Using the update() method t2 = timeit.timeit(stmt="my_dict.update({'JavaScript': 1995})", number=1000000, globals=globals()) # Using
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ append python dictionary to dictionary
Append Python Dictionary to Dictionary - Spark By {Examples}
May 31, 2024 - Python provides an update() method in dict class that can be used to append a new dictionary at the ending point of the given dictionary. The update() method allows the dictionary as an argument and adds its key-value pairs to the original ...
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-add-to-dictionary
Learn Python: How To Add to Dictionary (With Examples)
January 30, 2024 - So, when using this method, make sure the key youโ€™re using does not already exist in the dictionary, unless your intention is to update the value. Python makes it easy to add multiple items to a dictionary or update an existing item.
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ add-values-to-dictionary-python
How To Add Values To A Dictionary In Python - Flexiple
Assign Values Using Unique KeysMerging Two Dictionaries Using update()Add Values To Dictionary Using Two Lists Of The Same LengthConverting A List To The DictionaryAdd Values To Dictionary Using The merge( | ) OperatorAdd Values To Dictionary Using The in-place merge( |= ) Operator ... Python dictionaries are versatile and essential for managing key-value pairs in programming.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ adding-values-to-a-dictionary-of-list-using-python
Adding values to a Dictionary of List using Python
July 11, 2025 - Use the append() method to add values to the lists by accessing them through their keys. And, then print the dictionary.
๐ŸŒ
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.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-add-values-to-dictionary-in-python
How to Add Values to Dictionary in Python - GeeksforGeeks
July 23, 2025 - Explanation: {**a, **b} merges ... duplicate keys exist. update() method allows us to add multiple key-value pairs from another dictionary or an iterable of key-value pairs to an existing dictionary....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-dictionary
Python Dictionary - GeeksforGeeks
... d = { "name": "Kat", 1: "Python", (1, 2): [1,2,4] } # Access using key print(d["name"]) # Access using get() print(d.get("name")) ... New items are added to a dictionary using the assignment operator (=) by giving a new key a value.
Published ย  January 15, 2026
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ collections.html
collections โ€” Container datatypes
The dataclasses module provides a decorator and functions for automatically adding generated special methods to user-defined classes. Ordered dictionaries are just like regular dictionaries but have some extra capabilities relating to ordering operations. They have become less important now that the built-in dict class gained the ability to remember insertion order (this new behavior became guaranteed in Python 3.7).