Files
30-seconds-of-code/snippets/count_occurrences.md
Isabelle Viktoria Maciohsek c7e1ce2c06 Rename count_occurrences.md
2021-01-10 00:00:36 +02:00

18 lines
299 B
Markdown

---
title: count_occurrences
tags: list,beginner
---
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
```