Travis build: 156
This commit is contained in:
22
README.md
22
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]
|
||||
|
||||
<br>[⬆ 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)
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```py
|
||||
most_frequent([1,2,1,2,3,2,1,4,2]) #2
|
||||
```
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#contents)
|
||||
|
||||
### none
|
||||
|
||||
Returns `False` if the provided function returns `True` for at least one element in the list, `True` otherwise.
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
Reference in New Issue
Block a user