# filter()

say it: **“FIL-ter”** **/ˈfɪltər/**

Keeps only the items that pass a test.

## What does `filter()` do?

`filter()` keeps only the items that pass a test.

```python
ages = [12, 19, 35, 16]
adults = list(filter(lambda age: age >= 18, ages))
print(adults)  # [19, 35]
```

Level: Journeyman · [More Python terms at this level](https://www.ask-codey.com/glossary?category=python&level=3)

Updated: November 17, 2026

## In other subjects

- [filter() in Java](https://www.ask-codey.com/glossary/filter-java)
- [filter() in JavaScript](https://www.ask-codey.com/glossary/filter-javascript)

Source: https://www.ask-codey.com/glossary/filter
