Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-19 Thread Bernard Lebel
That is very interesting John. Thanks! Bernard On 5/19/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Quoting Bernard Lebel <[EMAIL PROTECTED]>: > > > Well, that was a nice explanation. Thanks once again Kent! > > There is a nice (not too technical) essay on the running speeds of differ

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-19 Thread Bernard Lebel
Well, that was a nice explanation. Thanks once again Kent! Bernard On 5/16/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > Bernard Lebel wrote: > > Hi Kent, > > > > So if I undestand you right, mapping a function with map() when it is > > a built-in function will/may be faster than a for loop, but

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-16 Thread Kent Johnson
Bernard Lebel wrote: > Hi Kent, > > So if I undestand you right, mapping a function with map() when it is > a built-in function will/may be faster than a for loop, but if it's a > custom function (ie. a def one), it will most likely be slower? I guess I didn't proofread that last mail...what I me

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-14 Thread Bernard Lebel
Thanks Alan, that clears things up quite well. Bernard On 5/14/05, Alan Gauld <[EMAIL PROTECTED]> wrote: > > So if I undestand you right, mapping a function with map() > > when it is a built-in function will/may be faster than a for > > loop, but if it's a custom function (ie. a def one), it wil

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-13 Thread Bernard Lebel
Hi Kent, So if I undestand you right, mapping a function with map() when it is a built-in function will/may be faster than a for loop, but if it's a custom function (ie. a def one), it will most likely be slower? Thanks Bernard On 5/13/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > Bernard Lebe

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-13 Thread Kent Johnson
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 ove

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-13 Thread Bernard Lebel
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. Cheers Bernard On 5/13/05, Alan Gauld <[EMAIL PROTECTED]> wrote: > How bizarre. I'm astonished that Lutz/Ascher even show that as a means > of

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-13 Thread Joe Healy
Alan Gauld wrote: >>now I always used map() to perform a looped call on a function that >>would change the attribute value, as shown in Mark Lutz & David >>Ascher's Learning Python: >> >># Perform attribute value change on a single instance >>def iterateInstances( oInstance ): >> oInstance.va

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-12 Thread Alan Gauld
> now I always used map() to perform a looped call on a function that > would change the attribute value, as shown in Mark Lutz & David > Ascher's Learning Python: > > # Perform attribute value change on a single instance > def iterateInstances( oInstance ): > oInstance.value = myValue > > #

Re: [Tutor] map() and lambda to change class instance attribute

2005-05-11 Thread Danny Yoo
> On Wed, 11 May 2005, Danny Yoo wrote: > > > map(lambda x: x^2, [1, 2, 3]) > > > > [x^2 for x in [1, 2, 3]] > > then we're really saying something like this: > > > > [1, 2, 3] > > | | | > > | | | map() > > | | | > > V

Re: [Tutor] map() and lambda to change class instance attribute

2005-05-11 Thread Terry Carroll
It's not often I get a chance to correct Danny, but On Wed, 11 May 2005, Danny Yoo wrote: > map(lambda x: x^2, [1, 2, 3]) > > [x^2 for x in [1, 2, 3]] > then we're really saying something like this: > > [1, 2, 3] > | | | > | | | map()

Re: [Tutor] map() and lambda to change class instance attribute

2005-05-11 Thread Bernard Lebel
Please tell them who reported them ;-) Bernard On 5/11/05, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > On Wed, 11 May 2005, Bernard Lebel wrote: > > > Thanks a lot for the advice. I will put that in practice. > > > > The blasphemous example is on page 227 of the second edition, under > > Mapp

Re: [Tutor] map() and lambda to change class instance attribute

2005-05-11 Thread Danny Yoo
On Wed, 11 May 2005, Bernard Lebel wrote: > Thanks a lot for the advice. I will put that in practice. > > The blasphemous example is on page 227 of the second edition, under > Mapping Functions Over Sequences. Hi Bernard, Ah, thank you. I'll start the Inquisition shortly. *grin* ___

Re: [Tutor] map() and lambda to change class instance attribute

2005-05-11 Thread Bernard Lebel
Hi Danny, Thanks a lot for the advice. I will put that in practice. The blasphemous example is on page 227 of the second edition, under Mapping Functions Over Sequences. Cheers Bernard On 5/11/05, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > I have to confess that I already use map(), or shou

Re: [Tutor] map() and lambda to change class instance attribute

2005-05-11 Thread Danny Yoo
> I have to confess that I already use map(), or should I say abuse, for > this, although it is the first time I consider using lambdas. Up until > now I always used map() to perform a looped call on a function that > would change the attribute value, as shown in Mark Lutz & David Ascher's > Learn

Re: [Tutor] map() and lambda to change class instance attribute

2005-05-11 Thread Bernard Lebel
Hi Danny, Thanks for the answer. I have to confess that I already use map(), or should I say abuse, for this, although it is the first time I consider using lambdas. Up until now I always used map() to perform a looped call on a function that would change the attribute value, as shown in Mark Lut

Re: [Tutor] map() and lambda to change class instance attribute (fwd)

2005-05-11 Thread Danny Yoo
-- Forwarded message -- Date: Wed, 11 May 2005 14:29:58 -0400 From: Bernard Lebel <[EMAIL PROTECTED]> To: Danny Yoo <[EMAIL PROTECTED]> Subject: Re: [Tutor] map() and lambda to change class instance attribute Hi Danny, Thanks for the answer. I have to confess th

Re: [Tutor] map() and lambda to change class instance attribute

2005-05-11 Thread Danny Yoo
> It is possible to abuse map() to do what you're trying to do, using the > setattr() function: > > ## Pseudocode > map(lambda instance: setattr(instance, 'value', 42)) > ## Hi Bernard, Grrr... I did label that as Pseudocode, but that doesn't excuse me from not actually trying to make t

Re: [Tutor] map() and lambda to change class instance attribute

2005-05-11 Thread Danny Yoo
On Wed, 11 May 2005, Bernard Lebel wrote: > Let say I have several class instances in a list, and these class > instances have an attribute named "value", whose value is an integer. > > I would like to know if it is possible to loop over the list of > instances to change their "value" attribute,

[Tutor] map() and lambda to change class instance attribute

2005-05-11 Thread Bernard Lebel
Hello, Let say I have several class instances in a list, and these class instances have an attribute named "value", whose value is an integer. I would like to know if it is possible to loop over the list of instances to change their "value" attribute, using a map( ( lambda:...), ... ) type of loo