Given a list, the task is to find the number of occurrences of the largest element of the list.

**Examples:**

Input :[1, 2, 8, 5, 8, 7, 8]Output :3Input :[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.

`# Python program to find the ` `# frequncy of largest element ` ` ` ` ` `L ` `=` `[` `1` `, ` `2` `, ` `8` `, ` `5` `, ` `8` `, ` `7` `, ` `8` `] ` ` ` `# print the frequency of largest element ` `frequency ` `=` `print` `(L.count(` `max` `(L))) ` ` ` ` ` ` ` ` ` |

*chevron_right*

*filter_none*

**Output:**

3

**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.

`# Python program to find the ` `# frequency of largest element ` ` ` `import` `collections ` ` ` `L ` `=` `[` `1` `, ` `2` `, ` `8` `, ` `5` `, ` `8` `, ` `7` `, ` `8` `] ` ` ` `# find the largest element ` `largest ` `=` `max` `(L) ` ` ` `# Storing the occurrences of each ` `# element of list in res ` `res ` `=` `collections.Counter(L) ` ` ` `print` `(res[largest]) ` |

*chevron_right*

*filter_none*

**Output:**

3

**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 program to find the ` `# frequency of largest element ` ` ` ` ` `L ` `=` `[` `1` `, ` `2` `, ` `8` `, ` `5` `, ` `8` `, ` `7` `, ` `8` `] ` `d` `=` `{} ` ` ` `# find the largest element ` `largest ` `=` `max` `(L) ` ` ` `for` `i ` `in` `L: ` ` ` `if` `i ` `in` `d: ` ` ` `d[i] ` `+` `=` `1` ` ` `else` `: ` ` ` `d[i] ` `=` `1` ` ` `print` `(d[largest]) ` |

*chevron_right*

*filter_none*

**Output:**

3

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.

## Recommended Posts:

- Python | Element with largest frequency in list
- Python - Find the frequency of numbers greater than each element in a list
- Maximum length prefix such that frequency of each character is atmost number of characters with minimum frequency
- Python - Element Frequency starting with K in dictionary value List
- Python - Sort by Frequency of second element in Tuple List
- Python | Largest, Smallest, Second Largest, Second Smallest in a List
- Python Program to Print Largest Even and Largest Odd Number in a List
- Generate a list using given frequency 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 the frequency of the elements which are common in a list of strings
- Python | Extract least frequency element
- Python | Tuple Column element frequency
- Python | Finding frequency in list of tuples
- Python | List frequency of elements
- Python | Sort list elements by frequency
- Python | Sort given list by frequency and remove duplicates
- Python | Group list elements based on frequency
- Python | Frequency grouping of list elements
- Python - Step Frequency of elements in List

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.