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.value = myValue >> >># Loop over list of instances >>map( iterateInstances, aListOfInstances ) >> >> > >How bizarre. I'm astonished that Lutz/Ascher even show that as a means >of changing an attribute. As Danny said, it's definitely an abuse of >map, >and there is no advantage whatsoever, as far as I can see. In fact I >suspect that it's actually slower than an explicit loop (because of >the extra list building). > > I have just been looking at http://www.python.org/moin/PythonSpeed/PerformanceTips#loops and whilst the examples do not show anything like this, they describe the map function as a for moved into C code. Could be confusing. Does not mention anything about return a list.
> > >>However I was looking into lambdas in hope to eliminate the need to >>define a function. >> >> > >And a loop also avoids the need for a function, and therefore for >a function call, which is another reason the map should be slower. > >Its completely weird that a text book should even suggest that map >be used for this! > >Alan G >Author of the Learn to Program web tutor >http://www.freenetpages.co.uk/hp/alan.gauld > >_______________________________________________ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > -- ________________________________________________________ Joe Healy | Engineer OMC-International | 6 Paterson St | Abbotsford, VIC 3067 Melbourne | Australia www.omc-international.com.au Dedicated to safer and more efficient shipping. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor