# Count Occurrences of an Item in a Python List

> Use the list.count method for a single item, or collections.Counter from the standard library to efficiently tally all unique items in a Python list

**URL:** https://sentry.io/answers/count-occurrences-of-item-in-python-list/

---

## The Problem

How do I count the occurrences of an item in a Python list?

## The Solution

We can use the Python [`list.count`](https://docs.python.org/3/tutorial/datastructures.html#more-on-lists) method, as below:

```python
products = ["Apple", "Orange", "Banana", "Pear", "Apple", "Banana"]

banana_count = products.count("Banana") # => 2
```

If we need to count the occurrences of every unique item in the list, it is more performant to use the [`Counter`](https://docs.python.org/3/library/collections.html#collections.Counter) collection from the built-in Python `collections` library than to use the `count` method in a loop.

```python
from collections import Counter
products = ["Apple", "Orange", "Banana", "Pear", "Apple", "Banana"]

element_counts = Counter(products)
```

This will produce a `Counter` object, which is a subclass of `dict`. For the code above, `element_counts` will look like this:

```python
Counter({"Apple": 2, "Orange": 1, "Banana": 2, "Pear": 1})
```

---

*Source: [sentry.io/answers/count-occurrences-of-item-in-python-list/](https://sentry.io/answers/count-occurrences-of-item-in-python-list/)*
