From 88bdc45108f3c53f5f3b68361398aa40ec1af3ea Mon Sep 17 00:00:00 2001
From: 30secondsofcode <30secondsofcode@gmail.com>
Date: Sat, 12 Oct 2019 10:16:11 +0000
Subject: [PATCH] Travis build: 156
---
README.md | 22 ++++++++++++++++++++++
snippet_data/snippetList.json | 15 +++++++++++++++
snippet_data/snippets.json | 20 ++++++++++++++++++++
3 files changed, 57 insertions(+)
diff --git a/README.md b/README.md
index 86642cfb6..e22e88462 100644
--- a/README.md
+++ b/README.md
@@ -54,6 +54,7 @@
* [`longest_item`](#longest_item)
* [`max_n`](#max_n)
* [`min_n`](#min_n)
+* [`most_frequent`](#most_frequent)
* [`none`](#none)
* [`offset`](#offset)
* [`sample`](#sample)
@@ -819,6 +820,27 @@ min_n([1, 2, 3], 2) # [1,2]
[⬆ Back to top](#contents)
+### most_frequent
+
+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)
+```
+
+
+Examples
+
+```py
+most_frequent([1,2,1,2,3,2,1,4,2]) #2
+```
+
+
+
[⬆ Back to top](#contents)
+
### none
Returns `False` if the provided function returns `True` for at least one element in the list, `True` otherwise.
diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json
index bdb5903a4..1d412d9f4 100644
--- a/snippet_data/snippetList.json
+++ b/snippet_data/snippetList.json
@@ -837,6 +837,21 @@
"hash": "c920b58f01c63346e65eab83a60c4635d4c104e41767b9d41ad94029e662b902"
}
},
+ {
+ "id": "most_frequent",
+ "type": "snippetListing",
+ "title": "most_frequent",
+ "attributes": {
+ "text": "Returns the most frequent element in a list.\n\nUse `set(list)` to get the unique values in the `list` combined with `max()` to find the element that has the most appearances.\n\n",
+ "tags": [
+ "list",
+ "beginner"
+ ]
+ },
+ "meta": {
+ "hash": "8f90ba8698b866c434ad0345df4753c46e1b19f01e339b00043a541d0e241db8"
+ }
+ },
{
"id": "n_times_string",
"type": "snippetListing",
diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json
index 3bc63ccb5..dd46bb7d6 100644
--- a/snippet_data/snippets.json
+++ b/snippet_data/snippets.json
@@ -1107,6 +1107,26 @@
"hash": "c920b58f01c63346e65eab83a60c4635d4c104e41767b9d41ad94029e662b902"
}
},
+ {
+ "id": "most_frequent",
+ "title": "most_frequent",
+ "type": "snippet",
+ "attributes": {
+ "fileName": "most_frequent.md",
+ "text": "Returns the most frequent element in a list.\n\nUse `set(list)` to get the unique values in the `list` combined with `max()` to find the element that has the most appearances.\n\n",
+ "codeBlocks": {
+ "code": "def most_frequent(list):\n return max(set(list), key = list.count)",
+ "example": "most_frequent([1,2,1,2,3,2,1,4,2]) #2"
+ },
+ "tags": [
+ "list",
+ "beginner"
+ ]
+ },
+ "meta": {
+ "hash": "8f90ba8698b866c434ad0345df4753c46e1b19f01e339b00043a541d0e241db8"
+ }
+ },
{
"id": "n_times_string",
"title": "n_times_string",