It is strange how much beauty varies for different people. I find the list comprehension much clearer than filter+lambda, but use whichever you find easier.

There are two things that may slow down your use of filter.

The first is the function call overhead: as soon as you use a Python function (whether created by def or lambda) it is likely that filter will be slower than the list comprehension. It almost certainly is not enough to matter, and you shouldn't think much about performance until you've timed your code and found it to be a bottleneck, but the difference will be there.

The other overhead that might apply is that the lambda is being forced to access a scoped variable (value). That is slower than accessing a local variable and in Python 2.x the list comprehension only accesses local variables. If you are using Python 3.x the list comprehension runs in a separate function so it will also be accessing value through a closure and this difference won't apply.

The other option to consider is to use a generator instead of a list comprehension:

def filterbyvalue(seq, value):
   for el in seq:
       if el.attribute==value: yield el

Then in your main code (which is where readability really matters) you've replaced both list comprehension and filter with a hopefully meaningful function name.

Answer from Duncan on Stack Overflow
🌐
KDnuggets
kdnuggets.com › 2022 › 11 › 5-ways-filtering-python-lists.html
5 Ways of Filtering Python Lists - KDnuggets
November 14, 2022 - Learn list comprehension with code examples by reading When to Use a List Comprehension in Python. scores = [200, 105, 18, 80, 150, 140] filtered_scores = [s for s in scores if s >= 150] print(filtered_scores)
Top answer
1 of 16
749

It is strange how much beauty varies for different people. I find the list comprehension much clearer than filter+lambda, but use whichever you find easier.

There are two things that may slow down your use of filter.

The first is the function call overhead: as soon as you use a Python function (whether created by def or lambda) it is likely that filter will be slower than the list comprehension. It almost certainly is not enough to matter, and you shouldn't think much about performance until you've timed your code and found it to be a bottleneck, but the difference will be there.

The other overhead that might apply is that the lambda is being forced to access a scoped variable (value). That is slower than accessing a local variable and in Python 2.x the list comprehension only accesses local variables. If you are using Python 3.x the list comprehension runs in a separate function so it will also be accessing value through a closure and this difference won't apply.

The other option to consider is to use a generator instead of a list comprehension:

def filterbyvalue(seq, value):
   for el in seq:
       if el.attribute==value: yield el

Then in your main code (which is where readability really matters) you've replaced both list comprehension and filter with a hopefully meaningful function name.

2 of 16
312

This is a somewhat religious issue in Python. Even though Guido considered removing map, filter and reduce from Python 3, there was enough of a backlash that in the end only reduce was moved from built-ins to functools.reduce.

Personally I find list comprehensions easier to read. It is more explicit what is happening from the expression [i for i in list if i.attribute == value] as all the behaviour is on the surface not inside the filter function.

I would not worry too much about the performance difference between the two approaches as it is marginal. I would really only optimise this if it proved to be the bottleneck in your application which is unlikely.

Also since the BDFL wanted filter gone from the language then surely that automatically makes list comprehensions more Pythonic ;-)

Discussions

Diffenence between List Comprehension and Map/Filter?
In Haskell, a list comprehension is just a syntactical form that allows you to combine a generator (an anamorphism) , a mapping or folding function, and a filter in a fairly expressive single-liner. From this standpoint, a list comprehension could be seen as a specialized syntax to combine high order functions that consume the results of a generator and that generator. More on reddit.com
🌐 r/functionalprogramming
13
10
September 24, 2023
Diffenence between List Comprehension and Map/Filter?
🌐 r/functionalprogramming
At what point are loops better than list comprehensions?
Readability is important, just after correctness. That means, in the initial approximation, speed/efficiency is less important. Until much later anyway. I wouldn't try to write that code as a comprehension. If, later, you need faster code you worry about algorithms first, not the low-level stuff. More on reddit.com
🌐 r/learnpython
56
32
July 30, 2023
Remove numbers from list with list comprehension
Are these numbers integers or strings? More on reddit.com
🌐 r/learnpython
5
2
August 15, 2021
🌐
Real Python
realpython.com › lessons › filtering-elements-list-comprehensions
Filtering Elements in List Comprehensions (Video) – Real Python
Conditional statements can be added to Python list comprehensions in order to filter out data. In this lesson, you learned how to use filtering to produce a list of even squares. The returned data is the same as before except for the fact that only even squares are returned.
Published   March 1, 2019
🌐
GeeksforGeeks
geeksforgeeks.org › python › filtering-elements-in-list-comprehension
Filtering Elements In List Comprehension - Python
July 23, 2025 - In Conclusion, leveraging list comprehensions for element filtering in Python not only streamlines code but also offers flexibility with concise and expressive syntax.
🌐
Plain English
python.plainenglish.io › incredibly-fast-ways-to-filter-lists-in-python-76fce2e06cd5
Incredibly Fast Ways to Filter Lists in Python | by Naveen Pandey | Python in Plain English
September 15, 2023 - Running this code will give us the filtered list, which includes only ‘Mark’ and ‘Carry. The list comprehension checks if each person’s name contains the letter ‘a’ (case-insensitive) before adding them to the new list. While list comprehensions are simple and pythonic, some may find them visually un-appealing due to…
🌐
University of Pittsburgh
sites.pitt.edu › ~naraehan › python3 › list_comprehension.html
Python 3 Notes: List Comprehension
Python 3 Notes [ HOME | LING 1330/2330 ] List Comprehension << Previous Note Next Note >> On this page: list comprehension [f(x) for x in li if ...]. Filtering Items In a List Suppose we have a list. Often, we want to gather only the items that meet certain criteria.
🌐
Finxter
blog.finxter.com › python-lists-filter-vs-list-comprehension-which-is-faster
Python Lists filter() vs List Comprehension – Which is Faster? – Be on the Right Side of Change
This tutorial has shown you the filter() function in Python and compared it against the list comprehension way of filtering: [x for x in list if condition]. You’ve seen that the latter is not only more readable and more Pythonic, but also faster.
Find elsewhere
🌐
Reddit
reddit.com › r/functionalprogramming › diffenence between list comprehension and map/filter?
r/functionalprogramming on Reddit: Diffenence between List Comprehension and Map/Filter?
September 24, 2023 -

Is there any significant difference between List Comprehensions like in Python or JavaScript and the Higher Order Functions "Map" and "Filter" in functional languages?

It seems that both take a list and return a new list. It's just a different syntax, like this example in Python

squares = [x**2 for x in numbers]
squares = list(map(lambda x: x**2, numbers))

Semantically, they are identical. They take a list of elements, apply a function to each element, and return a new list of elements.

The only difference I've noticed is that higher order functions can be faster in languages like Haskell because they can be optimized and run on multiple cores.

Edit: ChatGPT gave me a hint about the differences. Is that correct?

Semantically, List Comprehensions and the map and filter functions actually have some similarities, since they are all used to perform transformations on elements of a list and usually return a new list. These similarities can lead to confusion, as they seem similar at first glance. Let's take a closer look at the semantics:

Transformation:

List Comprehensions: you use an expression to transform each element of the source list and create a new list with the transformed values.

Map: It applies a specified function to each element of the source list and returns a list with the transformed values.

Filtering: List Comprehensions: you can insert conditions in List Comprehensions to select or filter elements based on a condition.

filter: This function is used specifically to select elements from the source list that satisfy a certain condition.

The semantic differences are therefore:

List Comprehensions can combine both transformations and filtering in a single construction, making their syntax versatile.

map is restricted to transformations and creates a new list of transformed values.

filter specializes in selecting elements based on a condition and returns a list with the selected elements.

🌐
Medium
medium.com › @rahulkp220 › list-comprehensions-lambda-filter-map-and-reduce-functions-in-python-d7a1bc6cd79d
List Comprehensions, lambda, filter, map and reduce functions in Python | by Rahul Lakhanpal | Medium
April 19, 2016 - List Comprehensions, lambda, filter, map and reduce functions in Python For a complete newbie, using these functions is not usual, unless they discover about them one day. Well this post is intended …
🌐
ZetCode
zetcode.com › python › filter-list
Python filter list - filtering lists in Python
January 29, 2024 - The filter is a built-in function which returns iterator from those elements of iterable that satisfy the given predicate. The function predates list comprehensions; it is generally recommended to use list comprehensions. ... #!/usr/bin/python words = ['sky', 'cloud', 'wood', 'forest', 'tie', ...
🌐
DEV Community
dev.to › theramoliya › list-comprehensions-for-filtering-and-transforming-lists-2foj
List Comprehensions for Filtering and Transforming Lists - DEV Community
September 26, 2023 - The basic syntax is: ... You can include a condition to filter items from the iterable based on certain criteria. The syntax is: new_list = [expression for item in iterable if condition]
🌐
Quantifiedcode
docs.quantifiedcode.com › python-anti-patterns › readability › using_map_or_filter_where_list_comprehension_is_possible.html
Using map() or filter() where list comprehension is possible — Python Anti-Patterns documentation
For simple transformations that can be expressed as a list comprehension, use list comprehensions over map() or filter(). Use map() or filter() for expressions that are too long or complicated to express with a list comprehension.
🌐
Recology
recology.info › list comprehension vs. filter vs. key lookup
List comprehension vs. filter vs. key lookup | Recology
April 18, 2022 - List comprehension: This is how I did the list comprehension method. Filter the list lst where some attibute matched some value.
🌐
Quora
quora.com › Is-it-better-to-use-list-comprehensions-or-filter-lambda-in-Python
Is it better to use list comprehensions or filter() +lambda in Python? - Quora
Answer (1 of 2): LIST COMPREHENSION [code]even = [i for i in range(101) if i%2==0] print(even) [/code]FILTER + LAMBDA [code]even = filter(lambda n : n%2 == 0, range(101)) print(list(even)) [/code]If you want the code which is faster, I would tell you to choose the filter() + lambda. It is the f...
🌐
Finxter
blog.finxter.com › home › learn python blog › how to filter a list in python?
How to Filter a List in Python? - Be on the Right Side of Change
July 14, 2022 - The most Pythonic way of filtering a list—in my opinion—is the list comprehension statement [x for x in list if condition]. You can replace condition with any function of x you would like to use as a filtering condition.
🌐
Medium
medium.com › swlh › python-list-comprehensions-vs-map-list-filter-functions-ebf0f8efe0e9
Python List Comprehensions vs. Map/List/Filter Functions | by Jonathan Craig | The Startup | Medium
November 8, 2020 - As you can see, the list comprehension version of this computation is a bit more unweildy and harder to intuit. Can’t win them all I suppose :\ There isn’t much more to say about filter() over map() the return the same kind of internally simple iterable object which doesn’t allow access to it’s elements directly.
🌐
DEV Community
dev.to › pedrexus › python-list-comprehensions-and-map-filter-and-reduce-g3o
Python list comprehensions and map, filter and reduce - DEV Community
March 20, 2024 - List comprehensions are so powerful we could actually perform the three operations of filter(), map() and reduce() in a single line of code with python!
🌐
O'Reilly
oreilly.com › library › view › python-cookbook › 0596001673 › ch01s11.html
Using List Comprehensions Instead of map and filter - Python Cookbook [Book]
July 19, 2002 - In Python 1.5.2, the solution is quite complex: thenewlist = map(lambda x: x+23, filter(lambda x: x>5, theoldlist)) A list comprehension affords far greater clarity, as we can both perform selection with the if clause and use some expression, such as adding 23, on the selected items:
Authors   Alex MartelliDavid Ascher
Published   2002
Pages   608
🌐
DEV Community
dev.to › bybydev › top-3-methods-to-filter-a-list-in-python-19fe
Top 3 methods to filter a list in Python - DEV Community
May 3, 2024 - Python offers versatile list filtering through list comprehensions, filter() function with lambda expressions, or comprehensible conditional statements for concise data manipulation.
🌐
The Renegade Coder
therenegadecoder.com › code › how-to-write-a-list-comprehension-in-python
How to Write a List Comprehension in Python: Modifying and Filtering – The Renegade Coder
May 25, 2020 - While duplicating and modifying lists is fun, sometimes it’s helpful to be able to filter a list: my_list = [2, 5, -4, 6] output = [item for item in my_list if item < 0] # [-4] In this case, we’ve added a new expression to the rightmost portion of the list comprehension that reads: if item < 0.