From 907bb897054b0ee6538ef7004651d2f9d63f6810 Mon Sep 17 00:00:00 2001 From: Lazar Gugleta Date: Sat, 12 Oct 2019 12:07:20 +0200 Subject: [PATCH] fix snippet most frequent --- snippets/most_frequent.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/snippets/most_frequent.md b/snippets/most_frequent.md index 926d0dddd..69b677626 100644 --- a/snippets/most_frequent.md +++ b/snippets/most_frequent.md @@ -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 -``` - +``` \ No newline at end of file