Merge pull request #134 from lazargugleta/fix/snippets

Add most_frequent snippet
This commit is contained in:
Angelos Chalaris
2019-10-12 13:14:47 +03:00
committed by GitHub

17
snippets/most_frequent.md Normal file
View File

@ -0,0 +1,17 @@
---
title: most_frequent
tags: list,beginner
---
Returns the most frequent element in a list.
Use `set(list)` to get the unique values in the `list` combined with `max()` to find the element that has the most appearances.
```py
def most_frequent(list):
return max(set(list), key = list.count)
```
```py
most_frequent([1,2,1,2,3,2,1,4,2]) #2
```