Why is map() preferable in this case?

2005-09-18 Thread Ray
Hello, I'm just reading the latest edition of Python Cookbook, where it says in Recipe 4.2: "when the op you wanna perform on each item is to call a function on the item and use the function's result, use L1 = map(f, L), rather than L1 = (f(x) for x in L)" What is wrong with the generator expres

Re: Why is map() preferable in this case?

2005-09-18 Thread Devan L
Ray wrote: > Hello, > > I'm just reading the latest edition of Python Cookbook, where it says > in Recipe 4.2: > > "when the op you wanna perform on each item is to call a function on > the item and use the function's result, use L1 = map(f, L), rather than > L1 = (f(x) for x in L)" > > What is wro

RE: Why is map() preferable in this case?

2005-09-19 Thread Delaney, Timothy (Tim)
Devan L wrote: > Map is in C. It's faster, but not as clear. Some people do think > map(f, L) is nicer though. Google is your friend here, if you want to > read the old arguments. map() will be faster if the function you are calling from map() is *also* in coded in C. If it's coded in python, the

Re: Why is map() preferable in this case?

2005-09-19 Thread Steven Bethard
Delaney, Timothy (Tim) wrote: > Devan L wrote: > >>Map is in C. It's faster, but not as clear. Some people do think >>map(f, L) is nicer though. Google is your friend here, if you want to >>read the old arguments. > > map() will be faster if the function you are calling from map() is > *also* in

Re: Why is map() preferable in this case?

2005-09-19 Thread Ray
Delaney, Timothy (Tim) wrote: > map() will be faster if the function you are calling from map() is > *also* in coded in C. If it's coded in python, then the generator > expression will probably be faster. > > Use whatever reads better to you. Look at optimising when you need to, > and not before.