Nest all content into snippets
This commit is contained in:
21
snippets/python/s/count-occurrences.md
Normal file
21
snippets/python/s/count-occurrences.md
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
title: Count occurrences
|
||||
type: snippet
|
||||
language: python
|
||||
tags: [list]
|
||||
cover: pineapple-at-work
|
||||
dateModified: 2021-01-10T00:00:36+02:00
|
||||
---
|
||||
|
||||
Counts the occurrences of a value in a list.
|
||||
|
||||
- Use `list.count()` to count the number of occurrences of `val` in `lst`.
|
||||
|
||||
```py
|
||||
def count_occurrences(lst, val):
|
||||
return lst.count(val)
|
||||
```
|
||||
|
||||
```py
|
||||
count_occurrences([1, 1, 2, 1, 2, 3], 1) # 3
|
||||
```
|
||||
Reference in New Issue
Block a user