In 2.7 and 3.1, there is the special Counter (dict subclass) for this purpose.

>>> from collections import Counter
>>> Counter(['apple','red','apple','red','red','pear'])
Counter({'red': 3, 'apple': 2, 'pear': 1})
Answer from Odomontois on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › count-dictionaries-in-a-list-in-python
Count dictionaries in a list in Python - GeeksforGeeks
July 12, 2025 - The program only creates a single list comprehension and a few variables to store the input list and the result. Method #2: Using recursion + isinstance() ( for nested dictionaries) The combination of above functionalities can be used to solve this problem. In this, we also solve the problem of inner nesting using recursion. ... # Python3 code to demonstrate working of # Dictionary Count in List # Using recursion + isinstance() # helper_func def hlper_fnc(test_list): count = 0 if isinstance(test_list, str): return 0 if isinstance(test_list, dict): return hlper_fnc(test_list.values()) + hlper_f
🌐
Reddit
reddit.com › r/learnpython › conversion between list and dictionary
r/learnpython on Reddit: conversion between list and dictionary
November 1, 2021 - It's O(n2) in the worst case (~N unique keys => loop through entire list N times to count occurrences). The set conversion in that code saves a lot of time if you only have a couple unique keys. ... If you want to use comprehension you can use set to create a unique list. dict = {element:lst.count(element) for element in list(set(lst))}
🌐
Built In
builtin.com › software-engineering-perspectives › convert-list-to-dictionary-python
10 Ways to Convert Lists to Dictionaries in Python | Built In
Converting a list to a dictionary with the same value for all keys. Converting a list to a dictionary using dict.fromkeys(). Converting a nested list to a dictionary using dictionary comprehension. Converting a list to a dictionary using Counter(). An introduction on how to convert a list to dictionary in Python...
🌐
Reddit
reddit.com › r/learnpython › how do i count a certain key value in a list python
r/learnpython on Reddit: how do I count a certain key value in a list python
January 24, 2022 -

I am trying to count how many times "yes" value appears in the done key but every time i rune the script i end up with a 0 can someone help please ?

list=[{"task":"walk dog", "done":"yes"},
      {"task":"talk", "done":"yes"},
      {"task":"sleep", "done":"yes"},
      {"task":"eat", "done":"no"},
      {"task":"chicken", "done":"yes"},
      {"task":"smoke", "done":"yes"} 
     ]

c = 0

for item in list:
  if list[1] == "yes":
    c= c+1
print(c)
🌐
DevQA
devqa.io › count-occurance-elements-list-python
How to Count the Occurrences of Each Element in a List using Python
July 8, 2023 - In this approach, we iterate through each element of the list and check if it already exists as a key in the count_dict. If it does, we increment its value by 1; otherwise, we add the element as a key with an initial value of 1. Finally, we ...
🌐
Stack Overflow
stackoverflow.com › questions › 58350482 › how-do-i-convert-list-with-word-count-into-a-dictionary
python - How do i convert list with word count into a dictionary - Stack Overflow
s = 'I want to make a dictionary ... 1 · Again we can use Counter which is faster. from collections import Counter s = list(s) print(Counter(s))...
🌐
Reddit
reddit.com › r/learnpython › how to get count of unique dictionaries in list?
r/learnpython on Reddit: How to get count of unique dictionaries in list?
December 23, 2020 -

Hi,

let's assume I have the following list:

a = [{'key': 'value1', 'key2': 'value2'},
     {'key': 'value1', 'key2': 'value2'},
     {'key': 'value3', 'key4': 'value5'}]

I would like to now get the count of each dictionary in this list, as a key: value in the dict.

Example output:

[{'key': 'value3', 'key4': 'value5', 'count': 1},
 {'key': 'value1', 'key2': 'value2', 'count': 2}]

Is there are a smarter way than some sort of loop? It should work but I would like to keep my O() down as much as possible.

I know that there are some examples for lists of strings or integers but they are all hashable types which dictionaries are not.

🌐
GeeksforGeeks
geeksforgeeks.org › python › counting-the-frequencies-in-a-list-using-dictionary-in-python
Counting the Frequencies in a List Using Dictionary in Python - GeeksforGeeks
October 25, 2025 - The defaultdict from the collections module automatically initializes new keys with a default value (in this case, 0), so there's no need to explicitly check if the key exists before incrementing the count. ... from collections import defaultdict a = ['apple', 'banana', 'apple', 'orange', 'banana', 'banana'] freq = defaultdict(int) for item in a: freq[item] += 1 print(dict(freq)) ... For each item in a, freq[item] += 1 increments its count. This will count the frequency of each item in the list using get() method.
Find elsewhere
🌐
w3resource
w3resource.com › python-exercises › dictionary › python-data-type-dictionary-exercise-34.php
Python: Count number of items in a dictionary value that is a list - w3resource
Write a Python program to count the number of items in a dictionary value that is a list. ... # Create a dictionary 'dict' with names as keys and lists of subjects as values. dict = {'Alex': ['subj1', 'subj2', 'subj3'], 'David': ['subj1', 'subj2']} # Calculate the total number of subjects by summing the lengths of the lists (values) in the dictionary.
🌐
Data Science Dojo
discuss.datasciencedojo.com › python
How to use a Python dictionary for counting? - Python - Data Science Dojo Discussions
May 11, 2023 - Hello everyone! I’m working on text analysis in Python and have stored my data from txt files in Python lists. Now, I need to count the frequency of words in the data. For instance, given this sample list: data_list = […
🌐
Python Guides
pythonguides.com › python-dictionary-count
Count Occurrences in Python Dictionary
January 12, 2026 - It is very helpful when you are building a complex Python dictionary count system. Unlike a regular Python dictionary, defaultdict automatically assigns a default value to a new key. from collections import defaultdict # List of professional US sports leagues leagues = ["NFL", "NBA", "MLB", "NFL", "NHL", "NBA", "NFL"] # Initialize defaultdict with int (which defaults to 0) league_counts = defaultdict(int) for league in leagues: league_counts[league] += 1 print(dict(league_counts))
🌐
Medium
medium.com › @dxsmith12 › efficiently-generating-a-python-dictionary-to-store-item-counts-a00e365767ef
Efficiently Generating a Python Dictionary to Store Item Counts | by Darren Smith | Medium
January 24, 2022 - import collections d = collections.defaultdict(int) sentence = 'the quick brown fox jumps over the lazy dog' for word in sentence.split(' '): d[word] += 1 print(d.items()) ... dict_items([('the', 2), ('quick', 1), ('brown', 1), ('fox', 1), ('jumps', 1), ('over', 1), ('lazy', 1), ('dog', 1)]) Lastly and most concisely is the use of the collections module’s Counter class. In the example below a Counter object may be created with letters (keys) and number of occurrences (values) contained within the list. Like the defaultdict, the Counter object is a subclass of the standard python dictionary and may be interacted with as if it was a standard dictionary.
🌐
Team Treehouse
teamtreehouse.com › community › counting-the-number-of-list-items-in-a-dictionarys-values
Counting the number of list items in a dictionary's values (Example) | Treehouse Community
December 2, 2017 - count_dict = {k: len(v) for k,v in d.items() if len(v) > 3 } The above would filter the return dict to keys whose list length is greater than 3, etc... Posting to the forum is only allowed for members with active accounts.
🌐
Educative
educative.io › answers › how-to-count-the-number-of-occurrences-of-a-list-item-in-python
How to count the number of occurrences of a list item in Python
The counter method is a collection where elements are stored as a dictionary with keys and counts as values. It takes one argument. ... Let’s look at an example of this. l = ['a', 'a', 'a', 'a', 'a', 'b', 'b', 'b', 'b', 'c', 'c', 'c', 'd', ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-convert-a-list-to-dictionary
Convert a List to Dictionary Python - GeeksforGeeks
For example, we are given a list a=[10,20,30] we need to convert the list in dictionary so that the output 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
🌐
Stanford
web.stanford.edu › class › archive › cs › cs106a › cs106a.1204 › handouts › lecture-18.html
Python "dict" type
The possible keys are 'breakfast', 'lunch', 'dinner', although a key may or not be present in the meals dict. bad_start() - check for bad breakfast - return True if no breakfast or if it is 'candy' ... def bad_start(meals): if 'breakfast' not in meals: return True if meals['breakfast'] == 'candy': return True return False # Can be written with "or" / short-circuiting avoids key-error # if 'breakfast' not in meals or meals['breakfast'] == 'candy': ... Counts dict: key for each distinct value value for each key is count how many times that key appears
🌐
Studytonight
studytonight.com › python-programs › counting-the-frequencies-in-a-list-using-dictionary-in-python
Counting the frequencies in a list using dictionary in Python - Studytonight
We will define a function that accepts the list as a parameter. Then we will create a dictionary where the list element is the key and its frequency will be the value. To get frequency we will traverse the list and check if the element is already present in the dictionary or not and keep a count accordingly...