Update most_frequent.md
This commit is contained in:
@ -3,9 +3,9 @@ title: most_frequent
|
|||||||
tags: list,beginner
|
tags: list,beginner
|
||||||
---
|
---
|
||||||
|
|
||||||
Returns the most frequent element in a `list`.
|
Returns the most frequent element in a list.
|
||||||
|
|
||||||
Use `set(list)` to get the unique values in the `list` in combination `max()` to find the element that has the most appearances.
|
Use `set(list)` to get the unique values in the `list` combined with `max()` to find the element that has the most appearances.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
def most_frequent(list):
|
def most_frequent(list):
|
||||||
@ -13,6 +13,5 @@ def most_frequent(list):
|
|||||||
```
|
```
|
||||||
|
|
||||||
```py
|
```py
|
||||||
numbers = [1,2,1,2,3,2,1,4,2]
|
most_frequent([1,2,1,2,3,2,1,4,2]) #2
|
||||||
most_frequent(numbers) #2
|
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user