Quick answer: filter(function, iterable) returns a lazy iterator containing the items for which function returns a truthy value. A lambda can express a short predicate, but a list comprehension is often clearer when the condition is simple and the result should be a new list.

Python filter() selects items from an iterable by applying a test function to each item. The official Python filter() documentation defines it as an iterator over the elements for which the function is true. A lambda expression is one compact way to write that test function.
The basic pattern is filter(function, iterable). The result is an iterator, not a list. Convert it with list() only when you actually need all matching items in memory.
Use filter() when the code reads clearly as “keep items matching this predicate.” Use a list comprehension when the condition is easier to read inline. Both approaches are normal Python; the better choice is the one that makes the filtering rule obvious.
Lambdas are best for short expressions. If the test needs several steps, logging, exception handling, or a useful name, write a regular function with def.
The most important detail is that filter() keeps items based on truthiness. The predicate does not have to return the literal value True; any truthy result keeps the item, and any falsey result removes it.
Filter Even Numbers With Lambda
This example keeps only even numbers. The lambda receives each number and returns True for values that should stay in the result.
numbers = [1, 2, 3, 4, 5, 6]
even_numbers = filter(lambda number: number % 2 == 0, numbers)
print(list(even_numbers))
The call to list() is only for display. In a pipeline, you can pass the filter object to another function that accepts any iterable.
This matters with large data sources because filter() produces values lazily. It does not build the whole output until something consumes it.
If you print the filter object itself, you will see an iterator representation rather than the kept values. Convert it to a list for debugging, or loop over it directly.
Filter Strings By Length
Lambdas work well for simple string checks. This example keeps names with at least five characters.
names = ["Ada", "Grace", "Linus", "Guido", "Edsger"]
long_names = filter(lambda name: len(name) >= 5, names)
print(list(long_names))
The predicate should return a truthy or falsey value. Returning a comparison, as shown here, keeps the intent direct.
If the rule becomes more complicated, name it. A named predicate improves tracebacks, reuse, and testability.

Use None To Remove Falsey Items
If the first argument is None, Python uses an identity test and removes falsey items such as empty strings, zero, False, and None.
raw_items = ["python", "", None, "filter", 0, "lambda"]
clean_items = filter(None, raw_items)
print(list(clean_items))
This is compact, but it removes every falsey value. Do not use it when 0 or False is valid data that should be preserved.
When the cleanup rule is specific, write it explicitly so future readers can see exactly what is being removed.
Use A Named Function For Reuse
A named function is clearer when the predicate has business meaning. It also makes the same rule easy to test.
def is_active_user(user):
return user["active"] and user["login_count"] > 0
users = [
{"name": "Maya", "active": True, "login_count": 4},
{"name": "Noor", "active": False, "login_count": 8},
{"name": "Luis", "active": True, "login_count": 0},
]
active_users = filter(is_active_user, users)
print([user["name"] for user in active_users])
The function name documents the filtering goal. The body documents the details of the rule.
This style is usually better than a long lambda, especially in shared code or tutorials where readers need to understand the condition quickly.
Named predicates are also easier to unit test. You can test is_active_user() with a few small dictionaries before using it in a filtering pipeline.
Compare filter With A List Comprehension
The Python docs note that filter(function, iterable) is equivalent to a generator expression when the function is not None. A list comprehension is often the clearest option when you want a list immediately.
A comprehension can also transform the items it keeps. The list comprehension if/else syntax guide separates a trailing filter from a leading conditional expression and shows how to combine them safely.
numbers = [3, 8, 11, 14, 17]
with_filter = list(filter(lambda number: number > 10, numbers))
with_comprehension = [number for number in numbers if number > 10]
print(with_filter)
print(with_comprehension)
Both results are the same. The comprehension avoids a small lambda and can be easier to scan.
Choose filter() when a reusable predicate already exists, when you want a lazy iterator, or when the pipeline style reads better. Choose a comprehension when the rule is short and the output should be a list.
For beginners, the comprehension often feels more direct because the condition appears beside the loop. For iterator-heavy code, filter() can keep each step focused.

Chain Filter With Other Iterables
Because filter() returns an iterator, it can be chained with other iterable tools. This example filters first, then transforms the kept values.
scores = [54, 91, 76, 88, 43, 99]
passing_scores = filter(lambda score: score >= 60, scores)
labels = map(lambda score: f"pass:{score}", passing_scores)
print(list(labels))
This pattern is useful for streaming-style processing, but do not over-chain simple logic. If a comprehension is clearer, use it. For related iterator transformations, see the Python map guide, and for text cleanup before filtering, see the Python split guide.
The practical rule is simple: keep lambdas short, convert the filter object only when needed, and use a named predicate when the condition matters enough to explain.
Also remember that a filter object is consumed as you iterate over it. If you need to reuse the result multiple times, store a list or recreate the filter from the original data.
Read The Function Signature
The first argument receives one item and returns a truth value; the second is the iterable. Passing the arguments in the wrong order or returning a transformed value instead of a predicate changes the result.

Remember Laziness
In Python 3, filter returns an iterator. It is consumed once, so convert it to list when a reusable snapshot is required, or iterate directly when streaming values is preferable.
Handle None As A Predicate
filter(None, iterable) keeps truthy items and removes falsey values such as 0, empty strings, and None. Use an explicit lambda or function when falsey values are valid data that should be retained.
Compare A Comprehension
A comprehension such as [value for value in values if value > 0] puts the output and condition in one readable expression. filter is useful when the predicate is already a named function or a lazy pipeline is desired.

Avoid Hidden Side Effects
Predicates should normally inspect an item and return a result. Side effects make lazy evaluation surprising because the function runs only when the iterator is consumed, not when filter is created.
Test Empty And Mixed Inputs
Test empty iterables, strings, generators, falsey values, and predicates that return non-Boolean truthy objects. Verify whether the caller expects an iterator or a concrete collection.
The official filter documentation defines the lazy iterator behavior. Related Python Pool references include lists and tests.
For related collection patterns, compare list comprehensions, iteration, and predicate tests when choosing filter or lambda.
Frequently Asked Questions
What does filter() do in Python?
filter() returns an iterator containing values for which its function returns a truthy result.
How do I use filter() with lambda?
Pass a lambda that accepts one item and returns a Boolean-like result, followed by the iterable to test.
Why is filter() not showing a list?
In Python 3, filter() is lazy and returns an iterator; wrap it in list() or iterate over it when you need to consume the values.
Is a list comprehension clearer than filter() with lambda?
Often yes for simple conditions, because the condition is visible next to the output expression; choose the form that makes the predicate easiest to review.