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
Top answer
1 of 16
750

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
313

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 ;-)

🌐
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
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
September 19, 2023
List comprehension if-else
Yes you can do this, and I checked the docs for a source but it isn't there! [c.strip() if c else None for c in con] This is how you would do it, but I'm boggled why its not in the docs. Maybe I missed it and someone else can point it out? Link I was looking at: https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions edit: I think this isn't explicitly documented because it's really a ternary. Meaning this counts as an "expression". For example, its roughly the same as: >>> con = range(20) >>> [c & 1 for c in con] [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1] You are evaluating and storing the result of the ternary/expression. More on reddit.com
🌐 r/learnpython
12
41
December 27, 2021
🌐
GeeksforGeeks
geeksforgeeks.org › python › filtering-elements-in-list-comprehension
Filtering Elements In List Comprehension - GeeksforGeeks
July 23, 2025 - List comprehensions are a powerful and concise way to create lists in Python. One of their notable features is the ability to filter elements based on certain conditions.
🌐
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.

🌐
W3Schools
w3schools.com › python › python_lists_comprehension.asp
Python - List Comprehension
The expression is the current item in the iteration, but it is also the outcome, which you can manipulate before it ends up like a list item in the new list: ... The expression can also contain conditions, not like a filter, but as a way to manipulate the outcome: ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Find elsewhere
🌐
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 - With map() and filter() you are locked into being required to ONLY use iterables as the additional arguments after your method pointer. A list comprehension has no such limitations and you can do whatever the hell awesome amazing stuff you want with as much variations as you like in parameters.
🌐
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.
🌐
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.
🌐
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 Media
oreilly.com
O'Reilly Media - Technology and Business Training
Jose, a principal software engineer, trusts our learning platform to filter what his teams need to know to stay ahead.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-filter-list-elements-starting-with-given-prefix
Python - Filter list elements starting with given Prefix - GeeksforGeeks
July 12, 2025 - List comprehension iterates through each word in the list a and checks if it starts with the prefix p using the startswith() method. Words that meet the condition are added to the new list f which contains the filtered elements.
🌐
Lkhibra
lkhibra.ma › books › Python-for-Data-Analysis.pdf pdf
Python for Data Analysis Data Wrangling with pandas, NumPy & Jupyter
Python · for Data Analysis · Data Wrangling with pandas, NumPy & Jupyter · Wes McKinney · Third · Edition
🌐
Google
docs.cloud.google.com › gemini enterprise agent platform › google models
Google models | Gemini Enterprise Agent Platform | Google Cloud Documentation
May 8, 2026 - MedGemma A collection of Gemma 3 variants trained for performance on medical text and image comprehension.
🌐
Vultr Docs
docs.vultr.com › python › built-in › filter
Python filter() - Filter Collection Items | Vultr Docs
November 22, 2024 - The filter() function in Python provides a convenient way for filtering collections through a function that tests each element in the iterable to be true or false.
🌐
Medium
medium.com › @sylvia.shubhangsingh › list-comprehension-map-filter-and-reduce-functional-programming-making-our-life-easy-6b05b397ad8
List Comprehension, Map, Filter and Reduce- functional programming making our life easy!! | by Shubhang Singh | Medium
September 21, 2021 - These functions can take multiple parameters as input but can only execute a single expression; in other words, they can only perform a single operation. But yes, these function come very handy while working with collections like lists and ...
🌐
Udemy
udemy.com › it & software
Complete Data Science,Machine Learning,DL,NLP Bootcamp
June 19, 2026 - Explore dictionaries in Python by creating and accessing key-value pairs, updating, deleting, and iterating over entries. Learn dictionary methods, nested dictionaries, dictionary comprehension, shallow copy, and merging with unpacking. Dictionaries Assignments And Practise Questions0:06 ... Explore real world use cases of lists in Python, including a to-do list manager, inventory tracking, student grade analysis, and collecting user feedback.
Rating: 4.5 ​ - ​ 26.6K votes
🌐
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)
🌐
Wikidot
dnd2024.wikidot.com › magic-item:all
Magic Items - D&D 5e (2024)
Crafting of Magical Items · Consumable Magic Items Magic Items by Source Magic Items by Type
🌐
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…