Re: Python : map and filter vs for loops
The underlying implementation of map and filter are different than loops, even though they accomplish the same thing. Which idiom runs fastest can change from version to version.
Right now I think list comprehensions are the fastest.
So instead of
Code:
filter(f, range(2,25)),
the list comprehension would be
Code:
[x for x in range(2,25) if f(x)]
and instead of
Code:
map(cube, range(1, 11))
the list comprehension would be
Code:
[cube(x) for x in range(1,11)]