Given a list, the task is to find the number of occurrences of the largest element of the list.
Input : [1, 2, 8, 5, 8, 7, 8] Output :3 Input : [2, 9, 1, 3, 4, 5] Output :1
Method 1: The naive approach is to find the largest element present in the list using
max(list) function, then iterating through the list using a for loop and find the frequency of the largest element in the list. Below is the implementation.
Method 2: Using collections.Counter()
Once initialized, counters are accessed just like dictionaries. Also, it does not raise the KeyValue error (if key is not present) instead the value’s count is shown as 0.
Method 3: Using the dictionary
In this approach, the number of occurrences of each element is stored in a dictionary as a key-value pair, where key is the element and value is the frequency.
- Python | Element with largest frequency in list
- Python - Element Frequency starting with K in dictionary value List
- Python | Find sum of frequency of given elements in the list
- Python | Find frequency of given character at every position in list of lists
- Python program to find second largest number in a list
- Python program to find largest number in a list
- Python program to find N largest elements from a list
- Python | Find most frequent element in a list
- Python | Find most common element in a 2D list
- Python | Find most common element in each column in a 2D list
- Python - Find the index of Minimum element in list
- Python | Extract least frequency element
- Python | Tuple Column element frequency
- Python | List frequency of elements
- Python | Sort list elements by frequency
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.