fix snippet most frequent

This commit is contained in:
Lazar Gugleta
2019-10-12 12:07:20 +02:00
parent bd95708f8d
commit 907bb89705

View File

@ -1,19 +1,18 @@
---
title: most_frequent
tags: array,beginner
tags: list,beginner
---
Method return the most frequent element that appears in a `list`.
Returns the most frequent element in a `list`.
Upon calling the function, in return you a `value`, which most frequently appears in the `list`.
Use `set(list)` to get the unique values in the `list` in combination `max()` to find the element that has the most appearances.
```py
def most_frequent(list):
return max(set(list), key = list.count)
return max(set(list), key = list.count)
```
```py
numbers = [1,2,1,2,3,2,1,4,2]
most_frequent(numbers) #2
```
```