0

If list comprehension is better than filter, as it performs slighly better and is considered more readable (arguably, in my opinion), why does filter even exist?

I use it all the time, but if the consensus is that list comprehensions are better, what are the reasons why we have the filter function?

Community
  • 1
  • 1
dabadaba
  • 9,064
  • 21
  • 85
  • 155
  • 1
    It almost didn't exist. http://www.artima.com/weblogs/viewpost.jsp?thread=98196 – OneCricketeer May 03 '17 at 17:41
  • 1
    From Guido himself: [here](http://www.artima.com/weblogs/viewpost.jsp?thread=98196) – roganjosh May 03 '17 at 17:41
  • While not an answer, I think it's interesting to note the emphasis on 'beauty' in python; in several places, list comprehension is posed as an alternative for those who don't view filter as 'beautiful' -- or vice versa. http://book.pythontips.com/en/latest/map_filter.html http://stackoverflow.com/questions/3013449/list-filtering-list-comprehension-vs-lambda-filter – Mr.Budris May 03 '17 at 17:41

1 Answers1

1

Way, way back in the day, way before we had list comprehensions, some guy who liked functional programming wrote up map and filter and submitted the change, and it got put in. That's about it.

user2357112
  • 260,549
  • 28
  • 431
  • 505