0
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?
2 odpowiedzi
+ 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.
0
Kevin Dietrichstein Usually, map and filter are slower.