Why does one work, but not the other?

j_mckitrick j_mckitrick at bigfoot.com
Fri Jun 18 20:34:25 CEST 2004


Peter Otten <__peter__ at web.de> wrote in message news:<cauk4d$b4n$00$1 at news.t-online.com>...
> j_mckitrick wrote:
> 
> > But I'm still on my mission to replace 'for' with list comprehensions
> > where possible, according to the article on optimization on the python
> > site.
> 
> I don't know the article, but I assume it doesn't tell list comprehensions
> are always faster/better. 

from http://www.python.org/doc/essays/list2str.html:

Try to use map(), filter() or reduce() to replace an explicit for
loop, but only if you can use a built-in function: map with a built-in
function beats for loop, but a for loop with in-line code beats map
with a lambda function!


I remember another, but can't find it right now.



More information about the Python-list mailing list