Python Program to Find Frequency of Elements in a List

Program Code

def frequency(list):
    unique_list = set(list)
    for item in unique_list:
        print(item, ":", list.count(item))

list = [1, 2, 3, 1, 2, 3, 2, 2, 4, 5, 5]

Code Explanation

  1. We first create a set of the list. A set is a collection of unique items.
  2. We then loop through the set and print the item and the number of times it occurs in the list.

Leave a Comment

Share to...