Python List Comprehensions vs Map/Filter

Comments debate the merits of Python list comprehensions versus map, filter, and reduce functions, focusing on readability, pythonic style, and functional versus imperative programming preferences.

📉 Falling 0.3x Programming Languages
2,760
Comments
20
Years Active
5
Top Authors
#278
Topic ID

Activity Over Time

2007
9
2008
52
2009
80
2010
85
2011
127
2012
132
2013
123
2014
177
2015
209
2016
195
2017
211
2018
179
2019
165
2020
126
2021
218
2022
180
2023
207
2024
162
2025
121
2026
2

Keywords

artima.com PEP572 HAVING viewpost.jsp python.org FP timeit.html CTE comprehensions map list filter comprehension python loops functional loop generators

Sample Comments

astrofinch Jun 13, 2011 View on HN

What's the rationale for preferring map/filter over list comprehensions?

frewsxcv Mar 30, 2015 View on HN

Use list comprehensions instead of map or filter. They're much easier to read.

icebraining Apr 10, 2016 View on HN

Are lists comprehensions (the proposed alternative) less "functional" than map/reduce/filter?

jburwell Mar 26, 2013 View on HN

What is the benefit of list comprehensions over the trifecta of map, reduce, and filter?

snowpid Dec 30, 2022 View on HN

List Comprehension is just syntax for functional coding (filter, map) but a very good one!

bkeroack Jul 9, 2014 View on HN

Depends on how you want to program: imperative vs functional.Personally I think list comprehensions are the most beautiful part of Python, though sometimes I use map() when I'm trying to be explicitly functional (I realize it's allegedly slower, etc).Generally I think list comprehensions are cleaner and allow you to write purer functions with fewer mutable variables. I disagree that deeply nested for loops are necessarily more readable.

pxndx Jul 3, 2018 View on HN

Python list comprehensions _are_ map/reduce.

Kaze404 Mar 31, 2020 View on HN

List comprehensions are "[x for x in list]". Map, reduce and filter are just functional constructs.

ubernostrum Mar 31, 2018 View on HN

It is becoming (has become?) an established part of the culture -- "Lambda in a `map`? Use a list comprehension instead."Which is annoying, because there are times when using map or filter is cleaner; for example, if you're doing pipeline-y stuff, using the function-based approach is much easier to read and reason about than doing a bunch of nested comprehensions.I also tend to think people don't use itertools enough. But it catches people by surprise enou

the-alchemist May 26, 2023 View on HN

It's a matter of comfort.I was doing imperative programming for years, and more functional now.You've got for loops, list comprehensions, newer dict comprehensions, map/filter, generators, etc. in Python.Python programmers tend to prefer for loops and comprehensions. List comprehensions, especially, dict comprehensions being much newer.Living mostly in the pre-Java 8 Java world, I used for loops as much as the next guy, like the rest of the Java world. But I really l