Write a Python program to display frequencies of all the elements of a list

List frequency of elements in Python

PythonServer Side ProgrammingProgramming

In this article, we are going to learn how to find the frequency of elements in a list. We can solve the problem in different ways. Let's see two of them.

Follow the below steps to write the code.

  • Initialize the list with elements and an empty dictionary.
  • Iterate over the list of elements.
    • Check whether the element is present in the dictionary or not.
    • If the element is already present in the dictionary, then increase its count.
    • If the element is not present in the dictionary, then initialize its count with 1.
  • Print the dictionary.

Python: Get the frequency of the elements in a list

Last update on April 13 2021 05:36:53 (UTC/GMT +8 hours)

Counting the frequencies in a list using dictionary in Python

Given an unsorted list of some elements(may or may not be integers), Find the frequency of each distinct element in the list using a dictionary.
Example:

Input : [1, 1, 1, 5, 5, 3, 1, 3, 3, 1, 4, 4, 4, 2, 2, 2, 2] Output : 1 : 5 2 : 4 3 : 3 4 : 3 5 : 2 Explanation : Here 1 occurs 5 times, 2 occurs 4 times and so on...

Recommended: Please try your approach on {IDE} first, before moving on to the solution.

The problem can be solved in many ways. A simple approach would be to iterate over the list and use each distinct element of the list as a key of the dictionary and store the corresponding count of that key as values. Below is the Python code for this approach:




# Python program to count the frequency of
# elements in a list using a dictionary
def CountFrequency(my_list):
# Creating an empty dictionary
freq = {}
for item in my_list:
if (item in freq):
freq[item] += 1
else:
freq[item] = 1
for key, value in freq.items():
print ("% d : % d"%(key, value))
# Driver function
if __name__ == "__main__":
my_list =[1, 1, 1, 5, 5, 3, 1, 3, 3, 1, 4, 4, 4, 2, 2, 2, 2]
CountFrequency(my_list)
Output: 1 : 5 2 : 4 3 : 3 4 : 3 5 : 2

Time Complexity:O(N), where N is the length of the list.



Alternative way: An alternative approach can be to use the list.count() method.




# Python program to count the frequency of
# elements in a list using a dictionary
def CountFrequency(my_list):
# Creating an empty dictionary
freq = {}
for items in my_list:
freq[items] = my_list.count(items)
for key, value in freq.items():
print ("% d : % d"%(key, value))
# Driver function
if __name__ == "__main__":
my_list =[1, 1, 1, 5, 5, 3, 1, 3, 3, 1, 4, 4, 4, 2, 2, 2, 2]
CountFrequency(my_list)
Output: 1 : 5 2 : 4 3 : 3 4 : 3 5 : 2

Time Complexity:O(N2), where N is the length of the list. The time complexity list.count() is O(N) alone, and when used inside loop it will become O(N2).

Alternative way:An alternative approach can be to use the dict.get() method. This makes the program much more shorter and makes understand how get method is useful instead of if…else.




# Python program to count the frequency of
# elements in a list using a dictionary
def CountFrequency(my_list):
# Creating an empty dictionary
count = {}
for i in [1, 1, 1, 5, 5, 3, 1, 3, 3, 1 ,4, 4, 4, 2, 2, 2, 2]:
count[i] = count.get(i, 0) + 1
return count
# Driver function
if __name__ == "__main__":
my_list =[1, 1, 1, 5, 5, 3, 1, 3, 3, 1, 4, 4, 4, 2, 2, 2, 2]
print(CountFrequency(my_list))
Output: {1: 5, 5: 2, 3: 3, 4: 3, 2: 4}

Related Article :
Count frequencies of all elements in array in Python using collections module

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course




Article Tags :
Python
frequency-counting
Python dictionary-programs
python-dict
python-list
Practice Tags :
python-dict
python-list

2. Python program to find the frequency of each element in the array

In this program, we have an array of elements to count the occurrence of its each element. One of the approaches to resolve this problem is to maintain one array to store the counts of each element of the array. Loop through the array and count the occurrence of each element as frequency and store it in another array fr.

In the given array, 1 has appeared two times, so its frequency is 2, and 2 has appeared four times so have frequency 4 and so on.

ALGORITHM:

  • STEP 1: Declare and initialize an array arr.
  • STEP 2: Declare another array fr with the same size of array arr. It is used to store the frequencies of elements present in the array.
  • STEP 3: Variable visited will be initialized with the value -1. It is required to mark an element visited that is, it helps us to avoid counting the same element again.
  • STEP 4: The frequency of an element can be counted using two loops. One loop will be used to select an element from an array, and another loop will be used to compare the selected element with the rest of the array.
  • STEP 5: Initialize count to 1 in the first loop to maintain a count of each element. Increment its value by 1 if a duplicate element is found in the second loop since we have counted this element and didn't want to count it again. Mark this element as visited by setting fr[j] = visited. Store count of each element to fr.
  • STEP 6: Finally, print out the element along with its frequency.

PROGRAM:

Output:

---------------------------------------- Element | Frequency ---------------------------------------- 1 | 2 2 | 4 8 | 1 3 | 1 5 | 1 ----------------------------------------

Counting the frequencies in a list using dictionary in Python

In this tutorial, you will learn to write a program in Python that will count the frequency of elements in a list using a dictionary. For a given list with multiple elements, we have to count the occurrence of each element in the list and display it as output. This can be done by creating a dictionary and using some built-in methods which will be discussed below.

Look at the input-output format to understand better.

Input: ['a', 'a', 'a', 'b','b']

Output: {'a': 3, 'b': 2}

To solve this problem we can follow these approaches-

  1. by iterating over the list and counting frequency
  2. using list.count() method
  3. using dict.get() method

“count frequency of elements in list python” Code Answer’s


how to get frequency of each elements in a python list
python by Frantic Ferret on May 24 2021 Comment
9
Source: buggyprogrammer.com
python count the frequency of words in a list
python by Andrea Perlato
Write a Python program to display frequencies of all the elements of a list
on Feb 25 2021 Donate Comment
1
Source: stackoverflow.com
list count frequency python
python by Cheerful Cormorant on Jul 15 2020 Comment
1
Source: stackoverflow.com
Add a Grepper Answer

  • numpy array count frequency
  • how to find no of times a elements in list python
  • python find number of occurrences in list
  • count occurrence in array python
  • python count number of unique elements in a list
  • find frequency of numbers in list python
  • count how many times a value shows in python list
  • count different values in list python
  • how to create frequency table in python
  • python count appearances in list
  • find all occurrences of an element in a list python
  • count number of occurrences of all elements in list python
  • count number of each item in list python

  • count frequency of elements in list python
  • get frequency of elements in list python
  • how to count frequency of elements in a list in python
  • frequency in list python
  • python frequency count of list
  • frequency of elements in list python
  • python get frequency of elements in list
  • count frequency of words in list python
  • frequency count list python
  • python get frequency of items in list
  • python count frequency of items in list
  • how to count word frequency in python
  • freq count in python
  • count the frequency of each element of an array python
  • count frequency of each element in a list python
  • frequency of elements in an array python
  • how to count frequency of list of lists python
  • how to check frequency of elements in list in python
  • frequency of list in python
  • frequency element python list
  • create frequency of values in a list python
  • how to count frequency of all elements in a list
  • how to count frequency of elements in a list in python 3
  • python calculate frequency in list
  • count frequency of item in list python
  • count frequency of numbers in list python
  • counting frequency of an element in python
  • python dictionary for frequency
  • python count word frequency
  • count object frequency in list
  • count frequency of element in list using list.count python using for loop
  • find the frequency of given numbers in list python
  • python count number frequency in list
  • how to find frequency of each element in array in python
  • number frequency counter python
  • list get frequency of item python
  • count frequency of elements in many lists
  • get the frequency of the elements in a list
  • frequency count in python
  • how to find the frequency of an element in a list in python
  • element frequency list python
  • how to get the frequency of values in a list python
  • python word frequency in a list
  • counting the frequency of elements in a list using a dictionary in python
  • how to count the frequency of elements ina alist in pyhton
  • fastest way to get the frequency of numbers of a list
  • how to find frequency of words in python
  • frequency of list of list python
  • find frequency of a word in python
  • frequency of an element in a list python
  • check word frequency in a list python
  • frequency of a word in a list python
  • calculate the frequency of occurrence of each character/integer in that list(count
  • count frequency of wods in list
  • count frequency of words in sentence python
  • python frequency table from list
  • counting the frequencies in a list using dictionary in python in anseding order
  • how to count the frequency of a word in python
  • frequency of array elements python
  • how to count a frequency of word in python
  • how to count frequency of letters in a word in python
  • how to get frequency of each elements in a python list
  • how to get frequency of each elements in a python
  • counting the most frequency of words in coulm python
  • get frequency of elements in array python
  • python count the frequency of words in a list and sort by value
  • find the frequency of elements in a list in python
  • how to find the frequency of an item in a list python
  • how to find the frequency of a number in a list in python
  • get the frequency of the elements in a list app no code
  • python list get element frequency
  • frequency in lists in python
  • python program to get the frequency of the elements in a given list of lists in python
  • frequency of a item python
  • list method to find frequency of an element in a list
  • count the frequency of a value in a list python
  • how to find frequency of an item in a python list
  • count frequency of each element in an list using python
  • frequency of values in list python np
  • frequency of element in list python
  • frequency of a elemnt in list in python
  • get the frequency of a element in an array python
  • find frequency of item in list python
  • how to get frequency of elements by index in python
  • calculate the frequency of each element in a list
  • function for frequency of occurence of a item in a list in python
  • return frequency of item in list python
  • how to find frequency of all elements in list in python
  • find frequency of list python map
  • find the frequency of each element in the list
  • list elements frequency python
  • how to find the frequency of a number in an array in python
  • find out the frequency of a element in python
  • frequency of an element in a list of lists python
  • frequency of a word in a list ython
  • python count frequency in dictionary
  • freqency in python
  • how to get frequency of list in python
  • count the frequency of all the list elements and store the frequency in a dictionary in python
  • how to count key frequency in python
  • python find frequency of element in list
  • write a python program to get the frequency of the elements in a list
  • count word frequency python
  • python frequency counter of list
  • frequency count dictionary python
  • count character frequency python
  • frequency of the elements in a list
  • counting frequnecies of elements in a list in python
  • how to count frequency of item in list python
  • find frequency of elements in python ,lst
  • frequency of output value python
  • frequency count in list in python using function
  • use switch to count frequency python
  • freuency of a list python
  • how to count the frequency of a value in python
  • python list count equal elements
  • use dictionary to count frequency python
  • frequency table from list python
  • display frequencies of words in an array using dictionaries python
  • counting the frequencies in a list using dictionary in python
  • python count number frequency
  • finding elements with equal frequency as its value in list python
  • key frequency python
  • to count the frequency of each word in the given string. python
  • count and frequency of list on words in panda
  • word frequency in a list python
  • create frequency of words in list python
  • count the frequency of words in python
  • count frequency of elements in series python
  • plot of values frequency in list python
  • count frequency of string in list python
  • word frequency counter in a list return list python
  • count frequency of each element in a string python
  • count frequency of words in list of string python
  • python count frequency of each word
  • python how to count the frequency of a specific word in a list
  • find the frequency of word python
  • frequency table from list counter python
  • list of frequency python
  • python frequency counter list
  • a list that count frequency of a element in python
  • frequency of list items python
  • python count element frequency in list
  • frequency on list python
  • count frequency of the values in a list
  • count frequency of element in adjacency list
  • find frequency of number in adjacency list python
  • python count list elements frequency
  • python check frequency of numbers
  • python count item frequency in list
  • fastest to count frequency in list oyhton
  • how to count frequency in list python
  • python count frequency in list
  • frequency of element in list python
  • wap to count frequency of a given element in a list of numbers.
  • how to count the frequency of elements in a list in python
  • python list frequency count
  • count frequency of an element in list python
  • maximum frequency python using dictionary
  • python get frequency of list
  • count the frequency of each element of a list python
  • frequency of numbers in list python
  • count frequency of element in list python
  • python frequency of number in list
  • python frequency of elements in list
  • counting the frequency of elements in a list
  • python count frequency of numbers in a list
  • find frequency of elements in list python
  • python count list frequency
  • check frequency of element in list python
  • find frequency of numbers in list python
  • python list group by count
  • how to find frequency of a number in a list in python
  • how to find frequency of a value in list in python
  • frequency in a list python
  • count frequency of a list python
  • python count frequency in array
  • list element frequency python
  • count frequency of one element in list python
  • frequency of list elements python
  • finding the frequency of elements in an array using python
  • python - count frequency of specific words in a text
  • frequency of word in list python
  • calculate frequency in python in a list
  • do not print the frequency of numbers in python
  • get frequency of value in list python
  • get frequency of elements in list pandas
  • how to find the frequency of each element in an array in python
  • how to count the frequency of an number on the list
  • find frequency of element in list python
  • find the frequency of a number in a list python
  • count frequency of elements in python
  • frequency python
  • how to find frequency of integers in list in python
  • how to get frequency in python in list
  • find the frequency of good words in a list python
  • frequency in python
  • frequency of words in list python
  • find frequency of each element in list python
  • frequency dict python
  • count number frequency python
  • count frequency of elements in a list python
  • count frequency of words in string python
  • get frequency of elements in list python in o(1)
  • find the frequency of each element in a list
  • how to count frequency of each element in array python
  • python frequency count of words
  • find frequency of string in list of strings python
  • find the frequency of characters in a list in python
  • check frequency of word in a list
  • python count the frequency of a word in a text based on dictionary
  • how count number of frequency word in a list
  • python count word frequency in string
  • how to get frequency of each elements in a python lis
  • frequency of all elements in list python
  • counting the most frequency of words in python
  • python count the frequency of words in a list
  • calculate highest frequency elements in list python
  • get the frequency of the elements in a list app
  • count frequency of elements in many lists o(n)
  • wap to count the frequency of an element in a given list in python
  • list all items with frequency int a python list
  • check frequency of element list
  • get frequency of array elements in python
  • get the frequency of the elements in a list tool
  • highest frequency elements in list python
  • how to find frequency of values in python
  • get the frequency of the elements in a list python numpy
  • get the frequency of the elements in a list.
  • finding frequency in list in python
  • how to get the frequency of an element in a list python
  • python program to find the frequency of each element in the array using function
  • get frequency of elements in list and make new list
  • get frequency of values in list python
  • how to get the frequency of words in a list in python
  • list find frequency of a element
  • frequency of list elements in python
  • best way to find frequency of numbers in a list
  • frequency of a list in python
  • find frequency of list python
  • find frequency elemeent in list
  • python frequency of item in list
  • make a frequency based on a list
  • count frequency of word in list python
  • python calculate frequency of words in list
  • python frequency of element in list
  • frequency count on ordered dictonary
  • no of frequency counter python
  • check frequency of number python
  • count in dictionary python
  • count the frequency of all the list elements and store the frequency in a dictionary.
  • make frequency array in pythin
  • find freqency in python
  • python get frequency
  • freq python
  • find frequency in list
  • python frequency list count
  • python group list by count
  • python get frequency
  • frequency in python
  • count frequency of list python
  • get frequency list python
  • how to count frequency of list in python
  • frequency of elements in list in python
  • python frequency of list
  • how to count the frequency of a value list python
  • make a list for frequency and number in python
  • count freq in python
  • counting the frequency of elements inside a list using .setdefault()
  • count frequency of numbers in a list
  • list duplicate frequency in array python
  • store a freq file into a dict python
  • frequency program python
  • python frequency using get()
  • python frequency of words in list
  • count frequency of words in python
  • count frequency of word in a list of strings python
  • how to count frequency of words in a string python
  • word frequency from list python
  • word frequency in list python
  • how to check frequency using list
  • count frequency in array library python
  • count frequency of values list
  • word frequency counter in a list python
  • count frequency of words python
  • how to count frequency of letters in a list in python
  • how to count the frequency of a specific word using for loop python
  • python how to count the frequency of a word in a list
  • python program to count the frequency of each word in a sentence
  • count element frequency pythonb
  • best way to count frequency in python list
  • count frequency from list
  • frequency count in list python
  • frequency count list
  • find frequency in list python
  • python list count frequency
  • python list frequency counter
  • count frequency range list python
  • python count value frequency in list
  • count frequency using list comprehension python
  • frequency counter python
  • count frequency in list
  • python count frequency
  • find frequency of a number in list python
  • python count frequency of elements in list
  • count frequency in list python
  • how to find frequency of elements in list in python
  • python frequency of items in list
  • python list count frequency
  • python frequency count
  • how to find frequency in python
  • how to get frequency of words in python
  • python frequency list
  • frequency of values in list python
  • list frequency python
  • python frequency count list
  • how to count frequency in dictionary python
  • frequency of a number in a list python
  • python get frequency of element in list
  • how to find a frequency of one array in python
  • python group list count
  • python count list element frequency
  • how to find frequency of number in list python
  • get the frequency of the elements in a list python
  • array list frequency of object in array list
  • how to count the frequency of an element in array in python
  • count frequency of each element in an array python
  • frequency of object in list python
  • python frequency count of list
  • python code to count frequency of a number in a list
  • how to find frequncy in python
  • how to count number frequency in python
  • count frequency of all elements in list python
  • python program to find frequency of elements in a list
  • how to count the frequency of an element in a list
  • count frequency of number in list python
  • how to count item frequency in python
  • count frequency of each item in list
  • frequency of the numbers in a list
  • frequency of each element in a list python
  • frequency of each element in list python
  • frequency of elements in a list python
  • how to find frequency of elements in an array in python
  • write a python program to count the frequency of each element in an array.
  • python list element frequency
  • frequency of items in list python
  • find frequency of words in a list python
  • python dictionary frequency
  • frequency i list in python
  • what is frequency of element in list python
  • how to find frequency of a occurrence of word in python
  • count frequency of each value in list in python
  • frequency of elements of no of elements in list
  • frequency of each element in python list using count
  • frequency of a specific word in a list python
  • how to count the frequency of a character in python
  • how to check every word frequency in python
  • how to find frequency of a word in python
  • count frequency words python
  • how to count frequency of words in python list
  • count couple words frequency in a list python
  • python find the frequency of word
  • how to count frequency of each character in a list in python
  • word list frequency counter python dictionary
  • get frequency of each element in list
  • how to get frequency of each elements in a python lists
  • how to find frequency of word in a list
  • how to count frequency of elements in a string in python
  • how to count frequency of words in python nupy array
  • frequency of element python list
  • python program to get the frequency of the elements in a given list of lists
  • python list frequency distribution
  • get the frequency of each element ina list of lists in python
  • calculate frequency in list python
  • frequency of each element in python 2 different list using count
  • print frequency of each element in array python
  • check frequency of array list
  • frequency of number in list python
  • count frequency of element in list using list.count python
  • frequency rate of each element in an array python
  • find frequency of each element in array python
  • function to count frequency of each elemnt in a list python
  • frequency of a number in list python
  • frequency of each element in list without built in functions python
  • how to count the frequency in a list
  • python program to find the frequency of each element in the array
  • how to get frequency of an element in list python
  • how to count the frequency of an object on the list
  • get frequency of a value in list python
  • frequency of each element in an array python
  • frequency of element in list python till k
  • code to find frequency of elements in array in python
  • how to find the frequency in python for list
  • count frequency of an elements in list python
  • frequencyof items in list
  • how to get frequency of numbers in a list python
  • python check frequency in list
  • python count frequency
  • number of occurrences of an element in a list in python dict
  • count freuencies of elements in list
  • frequency count on ordered dictonary python
  • frequency of values in a list
  • list get frequency
  • frequency of occurrences python
  • frequency list python count
  • how to count which element has the max frequency in py in lists
  • frequency of a value in a list python
  • frenquency count of python list
  • python frequency element liste
  • write a python program to get the frequency of the elements in a list without using dictionary
  • python get frequency from list
  • count feqcuyency of differents list in python
  • python list frequency table
  • frequency of values python
  • how to get frequency in python
  • how to make set of unique elements from freq count in python
  • frequency using dictionary in python
  • element *frequency list python
  • make a list for n number and frequency in python
  • understanding count frequency in python
  • python get number of same element in list without know them
  • count frequency of numbersin a list
  • calculating frequency of all elements of list in python
  • python get frequnecy of values in list
  • how to find the the most frequency word use in a dictionaryin python
  • frequency of occurences in a list python
  • python count frequency of words in list
  • get frequency of a word in python
  • python word frequency in list
  • frequency of words in a list python
  • how to count frequency of words in list in pyhton
  • python list frequency
  • python array counter frequency
  • how to count frequency of words in pyhton
  • find the frequency of good words in a list
  • list the words in sentence with frequency python
  • frequency of a word in list python
  • count frequency of words in a sentence python
  • how to count the frequency of a word using for loop python
  • python how to count the frequency of a word in a listy
  • how do i count the frequency of a word in a sentence python
  • frequency list python
  • best way to count frequency in -python
  • how to use frequency in list
  • count frequency of values in list python
  • frequency number in list
  • python count frequency of values in list
  • how to check the frequency of a number in a list
  • how to identify frequency in a given list in python program
  • count frequency of element in list using list.count python without using dictionary
  • frequency counting python
  • count frequency python
  • how to count the frequency of an element in a list python
  • how to count list data frequency in python
  • python list get frequency
  • find the frequency of a number in an array in python

Count frequency of elements in a list using for loop

We can count the frequency of elements in a list using a python dictionary. To perform this operation, we will create a dictionary that will contain unique elements from the input list as keys and their count as values.

To count the frequency of elements in the list, first, we will create an empty dictionary. After that, for each new element, we will count the frequency of the element in the list. After getting the frequency of the element, we will add the element and its frequency as key-value pair to the dictionary.

Write a Python program to display frequencies of all the elements of a list

We will also maintain a list of visited elements to filter out the elements that have been already visited. This can be done as follows.

myList = [1, 2, 3, 4, 1, 3, 46, 7, 2, 3, 5, 6, 10] frequencyDict = dict() visited = set() listLength = len(myList) for i in range(listLength): if myList[i] in visited: continue else: count = 0 element = myList[i] visited.add(myList[i]) for j in range(listLength - i): if myList[j+i] == element: count += 1 frequencyDict[element] = count print("Input list is:", myList) print("Frequency of elements is:") print(frequencyDict)

Output:

Input list is: [1, 2, 3, 4, 1, 3, 46, 7, 2, 3, 5, 6, 10] Frequency of elements is: {1: 2, 2: 2, 3: 3, 4: 1, 46: 1, 7: 1, 5: 1, 6: 1, 10: 1}

In the above example, we are iterating the whole list for each unique element. This makes the algorithm inefficient. In worst cases, when the list has all unique elements, we will have to process all the elements at least n*(n+1)/2 times where n is the length of the list.

To overcome this shortcoming, we will modify the above algorithm. As an improvement, we will iterate over the list only once. To count the frequency of elements, we will iterate through the list and check for each element if it is already present as a key in the dictionary or not. If the current element is already present as a key in the dictionary, we will increment the count associated with that element by 1. If the current element is not already present as a key in the dictionary, we will add a new item to the dictionary with the current element as key and 1 as its associated value.

We can implement this algorithm as follows.

myList = [1, 2, 3, 4, 1, 3, 46, 7, 2, 3, 5, 6, 10] frequencyDict = dict() visited = set() for element in myList: if element in visited: frequencyDict[element] = frequencyDict[element] + 1 else: frequencyDict[element] = 1 visited.add(element) print("Input list is:", myList) print("Frequency of elements is:") print(frequencyDict)

Output:

Input list is: [1, 2, 3, 4, 1, 3, 46, 7, 2, 3, 5, 6, 10] Frequency of elements is: {1: 2, 2: 2, 3: 3, 4: 1, 46: 1, 7: 1, 5: 1, 6: 1, 10: 1}

Improvisation to the above algorithm can be made using python try except blocks. In this method, we will use the try block to increment the frequency of the elements. Whenever an element is not already present in the dictionary, a KeyError will be raised. This will mean that the element is a unique element and its count hasn’t been added to the dictionary.

In the except block, we will catch the KeyError and add a new key-value pair to the dictionary with the current element as key and 1 as its associated value. This will be done as follows.

myList = [1, 2, 3, 4, 1, 3, 46, 7, 2, 3, 5, 6, 10] frequencyDict = dict() for element in myList: try: frequencyDict[element] = frequencyDict[element] + 1 except KeyError: frequencyDict[element] = 1 print("Input list is:", myList) print("Frequency of elements is:") print(frequencyDict)

Output:

Input list is: [1, 2, 3, 4, 1, 3, 46, 7, 2, 3, 5, 6, 10] Frequency of elements is: {1: 2, 2: 2, 3: 3, 4: 1, 46: 1, 7: 1, 5: 1, 6: 1, 10: 1}

Out of the above two algorithms, The solution which has been implemented using for loop will have almost the same efficiency for each type of input list. Whereas, the solution which uses exception handling will execute much faster for input lists having only a few elements repeated over many times in the list.