You just have to iterate the list and increment the count against the key if it is already there, otherwise set it to 1.

>>> d = {'a': 1, 'b': 2}
>>> l = ['a', 'b', 'c', 'd', 'e']
>>> for item in l:
...     if item in d:
...         d[item] += 1
...     else:
...         d[item] = 1
>>> d
{'a': 2, 'c': 1, 'b': 3, 'e': 1, 'd': 1}

You can write the same, succinctly, with dict.get, like this

>>> d = {'a': 1, 'b': 2}
>>> l = ['a', 'b', 'c', 'd', 'e']
>>> for item in l:
...     d[item] = d.get(item, 0) + 1
>>> d
{'a': 2, 'c': 1, 'b': 3, 'e': 1, 'd': 1}

dict.get function will look for the key, if it is found it will return the value, otherwise it will return the value you pass in the second parameter. If the item is already a part of the dictionary, then the number against it will be returned and we add 1 to it and store it back in against the same item. If it is not found, we will get 0 (the second parameter) and we add 1 to it and store it against item.


Now, to get the total count, you can just add up all the values in the dictionary with sum function, like this

>>> sum(d.values())
8

The dict.values function will return a view of all the values in the dictionary. In our case it will numbers and we just add all of them with sum function.

Answer from thefourtheye on Stack Overflow
๐ŸŒ
Quora
quora.com โ€บ How-do-I-add-a-list-to-a-Python-dictionary
How to add a list to a Python dictionary - Quora
Answer (1 of 9): The question is not clear. If I understood you correctly, you want to convert a list into a python dictionary. You need first to differentiate between the structure of the list and the dictionary. List = An array of elements (to reach an element, you use its index) Dictionary=...
Discussions

Appending to list in Python dictionary - Stack Overflow
What I am doing: I have keys and dates. There can be a number of dates assigned to a key and so I am creating a dictionary of lists of dates to represent this. The following code works fine, but I was hoping for a more elegant and Pythonic method. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Trying to insert a list inside the dictionary
Tiago Ramos is having issues with: Hi friends, I'm trying to insert this list inside the dictionary, this is the 3rd time I try. Please somebody show me how I do it, I wor... More on teamtreehouse.com
๐ŸŒ teamtreehouse.com
1
June 23, 2017
python - Appending a dictionary to a list - I see a pointer like behavior - Stack Overflow
6 What was the motivation for doing lists augmented assignment (+=) in place in python? 13 Python: append an original object vs append a copy of object ... 1 Unexpected behavior of append() method. Why, when adding a dictionary to the list, are the previous elements of the list overwritten? More on stackoverflow.com
๐ŸŒ stackoverflow.com
[Python 3] Add a value to a dictionary containing lists for each key, using a dict comprehension if the key already exists. Otherwise, if the key doesn't exist, create the key, value pair(value stored in list).

collections.defaultdict(list)?

More on reddit.com
๐ŸŒ r/learnpython
6
3
July 6, 2014
๐ŸŒ
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!

๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ how to append dictionary to list in python?
How to Append Dictionary to List in Python? - Spark By {Examples}
May 31, 2024 - The list.append() method is used to append an item to the list, so we can use this to append/add a dictionary to the list. In this first example, I will use the dict.copy() to create a shallow copy of the dictionary, and the return value will ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ appending-a-dictionary-to-a-list-in-python
Appending a Dictionary to a List in Python - GeeksforGeeks
July 23, 2025 - Let's explore different ways in which we can append a dictionary to a list in Python. append() method is the most straightforward and simple way to append a dictionary to a list. ... a = [{'name': 'kate', 'age': 25}] b = {'name': 'Nikki', 'age': ...
๐ŸŒ
Team Treehouse
teamtreehouse.com โ€บ community โ€บ trying-to-insert-a-list-inside-the-dictionary
Trying to insert a list inside the dictionary (Example) | Treehouse Community
June 23, 2017 - Just to recap, only imutable types can be keys (no lists, dictionaries, sets, user defined objects without a "hash" method), but anything can be a value. For example ยท my_dict = {} # Add a list: my_dict["my_list"] = [3, 1, 4, 1, 5, 9, 2] # Add a dictionary: my_dict["sub_dict"] = {"key": "value"} # Add a set: my_dict["my_set"] = set([3, 1, 4, 1, 5, 9, 2]) # Add a Tuple as a key and as a value: my_dict[(27.9878, 86.9250)] = ("Everest", "Nepal", 8848) # Prove it all worked: for key, value in my_dict.items(): print("Key: {}\nValue: {}\n\n".format(key,value))
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ appending-to-list-in-python-dictionary
Appending Element into a List in Python Dictionary - GeeksforGeeks
July 23, 2025 - Access the list using the dictionary key res['a'] and use append() method to add the element 4 to the list.
๐ŸŒ
Ubiq BI
ubiq.co โ€บ home โ€บ how to create dictionary from lists in python
How to Create Dictionary from Lists in Python - Ubiq BI
March 27, 2025 - In this article, we have learnt how to create dictionary from lists in Python. If you want to do the conversion directly without any exclusions or modifications to the list items, then you can use a combination of dict constructor and zip function.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-convert-a-list-to-dictionary
Convert a List to Dictionary Python - GeeksforGeeks
We are given a list we need to ... should be a dictionary like {0: 10, 1: 20, 2: 30}. We can use methods like enumerate, zip to convert a list to dictionary in python....
Published ย  July 12, 2025
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ appending-a-dictionary-to-a-list-in-python
Appending a dictionary to a list in Python
May 31, 2023 - There are other data types known as tuples and strings that belong to the sequence category. ... The elements should be quoted in double quotes and separated from each other using a comma. sample_list1 = ["List","Example","In","Python"] print(sample_list1) ... The Python dictionary may be thought of as an ordered collection of elements (starting with Python 3.7).
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dictionaries_add.asp
Python - Add Dictionary Items
Python Lists Access List Items ... Methods List Exercises Code Challenge Python Tuples ยท Python Tuples Access Tuples Update Tuples Unpack Tuples Loop Tuples Join Tuples Tuple Methods Tuple Exercises Code Challenge Python Sets ยท Python Sets Access Set Items Add Set Items Remove Set Items Loop Sets Join Sets Frozenset Set Methods Set Exercises Code Challenge Python Dictionaries...
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.3 documentation
To avoid getting this error when trying to access a possibly non-existent key, use the get() method instead, which returns None (or a specified default value) if the key is not in the dictionary. Performing list(d) on a dictionary returns a list of all the keys used in the dictionary, in insertion order (if you want it sorted, just use sorted(d) instead).
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-add-to-dictionary
How to Add and Update Python Dictionaries Easily | DigitalOcean
October 16, 2025 - However, dictionary keys are immutable and need to be unique within each dictionary. This makes dictionaries highly efficient for lookups, insertions, and deletions. 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.
๐ŸŒ
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.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dictionaries.asp
Python Dictionaries
List is a collection which is ordered and changeable. Allows duplicate members. Tuple is a collection which is ordered and unchangeable. Allows duplicate members. Set is a collection which is unordered, unchangeable*, and unindexed. No duplicate members. Dictionary is a collection which is ordered** and changeable. No duplicate members. *Set items are unchangeable, but you can remove and/or add items whenever you like. **As of Python version 3.7, dictionaries are ordered.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ collections.html
collections โ€” Container datatypes
Note that __missing__() is not called for any operations besides __getitem__(). This means that get() will, like normal dictionaries, return None as a default rather than using default_factory. defaultdict objects support the following instance variable: ... This attribute is used by the __missing__() method; it is initialized from the first argument to the constructor, if present, or to None, if absent. Changed in version 3.9: Added merge (|) and update (|=) operators, specified in PEP 584. Using list as the default_factory, it is easy to group a sequence of key-value pairs into a dictionary of lists:
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ typing.html
typing โ€” Support for type hints
1 week ago - # For creating a generic NamedTuple on Python 3.11 T = TypeVar("T") class Group(NamedTuple, Generic[T]): key: T group: list[T] # A functional syntax is also supported Employee = NamedTuple('Employee', [('name', str), ('id', int)]) Changed in version 3.6: Added support for PEP 526 variable annotation syntax. Changed in version 3.6.1: Added support for default values, methods, and docstrings. Changed in version 3.8: The _field_types and __annotations__ attributes are now regular dictionaries instead of instances of OrderedDict.