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.
    Disclaimer: While we make every effort to update the information, products, and services on our website and related platforms/websites, inadvertent inaccuracies, typographical errors, or delays in updating the information may occur. The material provided on this site and associated web pages is for reference and general information purposes only. In case of any inconsistencies between the information provided on this site and the respective product/service document, the details mentioned in the product/service document shall prevail. Subscribers and users are advised to seek professional advice before acting on the information contained herein. It is recommended that users make an informed decision regarding any product or service after reviewing the relevant product/service document and applicable terms and conditions. If any inconsistencies are observed, please reach out to us.

    Latest Articles

    Related Stories

    Leave A Reply

    Please enter your comment!
    Please enter your name here

    Join our newsletter and stay updated!