suppose your dictionary is named d and you want a count of the values:

from collections import Counter
d = {1: "dog", 2: "cat", 3: "dog", 4: "elephant"}
counts = Counter(d.values())

Now you can use the counts Counter:

# Values in the original dictionary
counts['dog'] # 2
counts['elephant'] # 1
# Value not in the original dictionary
counts['fish'] # 0

If you must use custom code and classes for this instead of the standard library, I think your error is here:

result.add((self.count(i), self.items[i]))

What you may want is:

animal_name = self.items[i] #?
result.add((self.count(animal_name), animal_name))

Otherwise you may want to share with us what is in self.items...

Answer from Reut Sharabani on Stack Overflow
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ dictionary โ€บ python-data-type-dictionary-exercise-61.php
Python: Count the frequency in a given dictionary - w3resource
June 28, 2025 - ... # Import the 'Counter' class ... a dictionary 'dictt' as an argument. def test(dictt): # Use the 'Counter' class to count the frequency of values in the dictionary....
๐ŸŒ
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 - ... 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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-frequencies-of-values-in-a-dictionary
Python - Frequencies of Values in a Dictionary - GeeksforGeeks
April 25, 2023 - In this, we perform the task of extraction of values using values() and frequency counter using Counter(). ... # Python3 code to demonstrate working of # Dictionary Values Frequency # Using Counter() + values() from collections import Counter ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ counting-the-frequencies-in-a-list-using-dictionary-in-python
Counting the frequencies in a list using dictionary in Python
August 23, 2019 - ... list = ['a','b','a','c','d... in list: if (item in frequency): frequency[item] += 1 else: frequency[item] = 1 for key, value in frequency.items(): print("% s -> % d" % (key, value)) Running the above code gives us the following result โˆ’ ... Here we use the in-built count() function to count the ...
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-dictionary-count
Count Occurrences in Python Dictionary
January 12, 2026 - If it exists, I increment the value; if it doesnโ€™t, I initialize it to one. A slightly more elegant way to handle a Python dictionary count is by using the .get() method. The .get() method is great because it prevents the โ€œKeyErrorโ€ that occurs when you try to access a key that isnโ€™t there yet. # List of popular American car brands cars = ["Ford", "Tesla", "Chevrolet", "Tesla", "Ford", "Ford", "Dodge"] car_count = {} for car in cars: # Use get to provide a default value of 0 if key is missing car_count[car] = car_count.get(car, 0) + 1 print(car_count)
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @tariq.tq โ€บ three-ways-to-count-frequency-fc0c5d32cea8
Comparing Approaches to Count the Frequency of Items in a List | by Tariq | Medium
April 29, 2023 - The approach makes use of a for loop to iterate through each element in the list and counts the number of occurrences using the count() function. The resulting dictionary contains the frequency of each element as key-value pairs.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ counting-word-frequency-and-making-a-dictionary-from-it
Counting Word Frequency and Making a Dictionary from it - GeeksforGeeks
July 23, 2025 - This method manually counts word frequencies by iterating through the list of words and updating a dictionary. ... a = "Python with Python gfg with Python" b = {} # Counting frequency using a loop for c in a.split(): b[c] = b.get(c, 0) + 1 print(b)
๐ŸŒ
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 = [โ€ฆ
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-dictionary-list-values-frequency
Python - Dictionary List Values Frequency - GeeksforGeeks
April 25, 2023 - In this, we use defaultdict() to initialize the counter for each value and brute force is used to increment the counter in dictionary lists. ... # Python3 code to demonstrate working of # Dictionary List Values Frequency # Using loop + defaultdict() ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
Write a Python Program to Count the Frequencies in a List Using Dictionary - YouTube
Hi, in this video I tried to explain how you can Write a Python Program to Count the Frequencies in a List Using DictionaryPython Scripts ===================...
Published ย  August 21, 2022
๐ŸŒ
Data Science Parichay
datascienceparichay.com โ€บ home โ€บ blog โ€บ count occurrences of a value in a python dictionary
Count Occurrences of a Value in a Python Dictionary - Data Science Parichay
February 12, 2022 - If you want to count the occurrences of each value in a Python dictionary, you can use the collections.Counter() function on the dictionary values.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 64866840 โ€บ frequency-count-given-a-dictionary-and-list
python - Frequency count given a dictionary and list - Stack Overflow
Thank you for the assistance. I like the idea of f strings and would like to learn more about these. This worked! 2020-11-16T23:31:30.053Z+00:00 ... Additional question: so if you wanted to find min(), would you reverse the sign in your if elements_count[item] > max_value line?
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ python-program-to-count-the-frequency-of-words-appearing-in-a-string-using-a-dictionary
Python Program to Count the Frequency of Words Appearing in a String Using a Dictionary
A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on). ... my_string = input("Enter the string :") my_list=[] my_list=my_string.split() word_freq=[my_list.count(p) for p in my_list] print("The frequency of words is ...") print(dict(zip(my_list,word_freq)))
๐ŸŒ
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 have created an empty dictionary and stored the list elements as keys and their frequency as values. def CountFreq(li): freq = {} for items in li: freq[items] = freq.get(items,0)+1 print(freq) li =['a', 'a', 1, 1, 1, 'b', 'b', 'b', 2, 2, ...