new_dict[word] += 1 This presumes it already has a value, and as written, will be the case. Answer from krathulu on reddit.com
🌐
TutorialsPoint
tutorialspoint.com › add-a-key-value-pair-to-dictionary-in-python
Add a key value pair to dictionary in Python
August 23, 2023 - CountryCodeDict = {"India": 91, "UK" : 44 , "USA" : 1, "Spain" : 34} print(CountryCodeDict) CountryCodeDict.update( {'Germany' : 49} ) print(CountryCodeDict) # Adding multiple key value pairs CountryCodeDict.update( [('Austria', 43),('Russia',7)] ) print(CountryCodeDict) Running the above code gives us the following result ? {'Spain': 34, 'India': 91, 'USA': 1, 'UK': 44} {'Germany': 49, 'Spain': 34, 'India': 91, 'USA': 1, 'UK': 44} {'USA': 1, 'India': 91, 'Austria': 43, 'Germany': 49, 'UK': 44, 'Russia': 7, 'Spain': 34} We can also append elements to a dictionary by merging two dictionaries.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › python dictionary append: how to add key/value pair?
Python Dictionary Append: How To Add Key/Value Pair?
October 14, 2024 - Here’s how it works: 1. Merging ... iterating over dict2 and adding each key-value pair individually, you can simply use the update() method....
Discussions

Add descriptions for keys in a dictionary
Hi, I learned that we can create a dictionary with key-value pairs in Python. So I wonder can I add some descriptions for my key-value pairs? such as: dict[key].description = "comment for my key-value pair" Is this feasible and how can I achieve this function? Thank you~ More on discuss.python.org
🌐 discuss.python.org
0
March 16, 2022
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
Returning a dictionary
First, I am new to Python and using the Python Crash Course by Eric Matthes to learn. I am somewhat puzzled with the code below. I think I understand that the function build_person() takes in the first and last name and puts them into a dictionary and then the value is returned to the call ... More on discuss.python.org
🌐 discuss.python.org
0
June 19, 2024
🌐
DataCamp
datacamp.com › tutorial › python-dictionary-append
Python Dictionary Append: How to Add Key-Value Pairs | DataCamp
August 6, 2024 - The .update() method modifies the existing dictionary in place by adding key-value pairs from another dictionary, potentially overwriting existing keys. The merge operator creates a new dictionary containing elements from both dictionaries, leaving the original dictionaries unchanged. ... 6.7MMaster the basics of data analysis with Python in just four hours.
🌐
Analytics Vidhya
analyticsvidhya.com › home › 5 methods to add new keys to a dictionary in python
5 Methods to Add New Keys to a Dictionary in Python
February 7, 2025 - Several methods are available in Python to add new keys to a dictionary. Let’s explore each of these methods in detail. One of the simplest ways to add a new key-value pair to a dictionary is by using the bracket notation.
🌐
GeeksforGeeks
geeksforgeeks.org › python › add-a-keyvalue-pair-to-dictionary-in-python
Add a key value pair to Dictionary in Python - GeeksforGeeks
For example, starting with dictionary d = {'key1': 'geeks', 'key2': 'for'}, we add multiple key-value pairs at once: 'key3': 'Geeks', 'key4': 'is', 'key5': 'portal', and 'key6': 'Computer'. After the update, the dictionary becomes {'key1': 'geeks', 'key2': 'for', 'key3': 'Geeks', 'key4': 'is', 'key5': 'portal', 'key6': 'Computer'}.
Published   July 11, 2025
🌐
Python.org
discuss.python.org › python help
Add descriptions for keys in a dictionary - Python Help - Discussions on Python.org
March 16, 2022 - Hi, I learned that we can create a dictionary with key-value pairs in Python. So I wonder can I add some descriptions for my key-value pairs? such as: dict[key].description = "comment for my key-value pair" Is this f…
🌐
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.

Find elsewhere
🌐
Sentry
sentry.io › sentry answers › python › add new keys to a dictionary in python
Add new keys to a dictionary in Python | Sentry
January 30, 2023 - You can also use the dictionary comprehension and dictionary constructor together to add or update the key-value pairs: ... prices = {**prices, **{"Pear": 2, "Grapefruit": 2, "Orange": 3}} print(prices) # will print {"Apple": 2, "Orange": 3, ...
🌐
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.
🌐
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.

🌐
Python.org
discuss.python.org › python help
Returning a dictionary - Python Help - Discussions on Python.org
June 19, 2024 - First, I am new to Python and using the Python Crash Course by Eric Matthes to learn. I am somewhat puzzled with the code below. I think I understand that the function build_person() takes in the first and last name and puts them into a dictionary and then the value is returned to the call statement which is assigned to the variable musician. type or paste code here def build_person(first_name, last_name): '''Return a dictionary of information about a person''' person = {'first': firs...
🌐
UiPath Community
forum.uipath.com › help › activities
How to add values to an already existing key in dictionary - Activities - UiPath Community Forum
March 6, 2021 - Hi! I’m trying to add new values to an already existing key in my dictionary. Let’s suppose I have the following dictionary: my_dict { ‘key_1’: ‘value_1’, ‘key_2’: ‘value_2’ } My goal, in this example, is to add the values on this list: [‘value_3’, ‘value_4’] either ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › append-a-value-to-a-dictionary-python
Append a Value to a Dictionary Python - GeeksforGeeks
July 23, 2025 - It creates a new dictionary rather than updating the original one in-place, which makes it slightly less efficient than update() method for small appends. ... Explanation: {**d, 'd': 4, 'e': 5} unpacks all key-value pairs from d ,adds 'd': 4 and 'e': 5 and creates a new 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))
🌐
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 to create two dictionaries and use the merge operator to create a new dictionary that contains the key-value pairs from both: site = {'Website':'DigitalOcean', 'Tutorial':'How To Add to a Python Dictionary', 'Author':'Sammy'} guests = {'Guest1':'Dino Sammy', 'Guest2':'Xray Sammy'}
🌐
Reddit
reddit.com › r/learnpython › how do you add a list as the value of a key inside a dictionary? what about tuples of lists?
r/learnpython on Reddit: How do you add a list as the value of a key inside a dictionary? What about tuples of lists?
April 3, 2022 -

I am trying to add a list, or a tuple of lists, as the value to a key inside a dictionary. I'm starting with a dictionary that has empty lists as values, and then adding to the value of each key inside a loop like this:

dict = {'key1': [], 'key2': [], 'key3': []}
list = ['a', 'b']
for key,value in dict.items():
#    dict[key].append(list)
    value.append(list)
print(dict)

What is the difference between dict[key].append(list) and value.append(list)? They both produce the same dictionary when the other is commented out.

Further, how would I add a second list to one of these values as a tuple? Something like adding the list ['c', 'd'] to key2, like this:

{'key1': [['a', 'b']], 'key2': [['a', 'b'], ['c', 'd']], 'key3': [['a', 'b']]}

Thanks for any replies!

🌐
W3Schools
w3schools.com › python › python_dictionaries_add.asp
Python - Add Dictionary Items
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict["color"] = "red" print(thisdict) Try it Yourself » · The update() method will update the dictionary with the items from a given argument. If the item does not exist, the item will be added. The argument must be a dictionary, or an iterable object with key:value pairs.
🌐
W3Schools
w3schools.com › python › python_dictionaries.asp
Python Dictionaries
In Python 3.6 and earlier, dictionaries are unordered. Dictionaries are written with curly brackets, and have keys and values: ... Dictionary items are ordered, changeable, and do not allow duplicates. Dictionary items are presented in key:value pairs, and can be referred to by using the key name.
🌐
Quora
quora.com › How-do-you-add-to-a-dictionary-in-Python
How to add to a dictionary in Python - Quora
Answer (1 of 16): To add a value you need a key (since a dictionary stores a key value pair). With the key then adding a value is easy : [code]the_dict[key] = value [/code]This will add a key to a dictionary if the key doesn’t exist, and replace the value being stored for that key if the ...
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.3 documentation
When the keys are simple strings, it is sometimes easier to specify pairs using keyword arguments: >>> dict(sape=4139, guido=4127, jack=4098) {'sape': 4139, 'guido': 4127, 'jack': 4098} When looping through dictionaries, the key and corresponding value can be retrieved at the same time using the items() method.