Files
30-seconds-of-code/snippets/count_occurences.md

18 lines
308 B
Markdown

---
title: count_occurences
tags: list,beginner
---
Counts the occurrences of a value in a list.
- Use the `count` method of Python's list object to count the number of occurrences.
```py
def count_occurrences(lst, val):
return lst.count(val)
```
```py
count_occurrences([1, 1, 2, 1, 2, 3], 1) # 3
```