List Comprehensions or map and fillter | Sololearn: Learn to code for FREE!

List Comprehensions or map and fillter

I am doing the python course, and I notice that functions for itrerables, such as map and filter, accomplish the same purpose than list comprehensions. So, what are the advantages and disadvantages of each approach?

24th Sep 2018, 4:30 PM
John Ortiz
John Ortiz - avatar
2 Respuestas
+ 1
list comprehensions are faster and more pythonic than map and filter. theres one case where map is faster than list comprehension, when you dont use an anonymous function (lambda), for instance: map(int(x), x). but nevertheless you should avoid using map and filter. even guido van rossum, the founder of python, said that it was a bad idea to add map and filter to the python syntax, as it doesnt add any speed advantage to your code.
24th Sep 2018, 8:37 PM
Kevin Dietrichstein
Kevin Dietrichstein - avatar
Kevin Dietrichstein Usually, map and filter are slower.
11th Jul 2021, 5:04 PM
Calvin Thomas
Calvin Thomas - avatar