[Tutor] map() and lambda to change class instance attribute (fwd)
Kent Johnson
kent37 at tds.net
Fri May 13 17:19:54 CEST 2005
Bernard Lebel wrote:
> The authors even go as far as saysing, on page 228 (first paragraph)
> that map() used that way has a performance benefit and is faster than
> a for loop.
That may well be correct, at least in the case where the function passed to map is a builtin.
Mapping a builtin to over a list is extremely fast. So write the code with a for loop so it is
clear. When you identify a performance bottleneck you can try rewriting your loop using map or list
comprehension, which is also fast. Until then it is premature optimization. For typical loops over a
small number of items I can't imagine you would notice the difference.
Kent
More information about the Tutor
mailing list