Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:43:50 +03:00
parent ab1ea476c5
commit a5ca5190e5
169 changed files with 0 additions and 626 deletions

View File

@ -0,0 +1,21 @@
---
title: Most frequent element
type: snippet
tags: [list]
cover: secret-tree
dateModified: 2020-11-02T19:28:27+02:00
---
Returns the most frequent element in a list.
- Use `set()` to get the unique values in `lst`.
- Use `max()` to find the element that has the most appearances.
```py
def most_frequent(lst):
return max(set(lst), key = lst.count)
```
```py
most_frequent([1, 2, 1, 2, 3, 2, 1, 4, 2]) #2
```