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
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
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
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
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.