[Python-3000] Need closure on __cmp__ removal
mike.klaas at gmail.com
Wed Jan 9 21:10:34 CET 2008
On 9-Jan-08, at 11:41 AM, Oleg Broytmann wrote:
> On Wed, Jan 09, 2008 at 11:34:59AM -0800, Brett Cannon wrote:
>> On Jan 9, 2008 11:34 AM, Oleg Broytmann <phd at phd.pp.ru> wrote:
>>> newlist = oldlist.sort(key=lambda v: v.attr_x)
>> And don't forget about operator.attrgetter().
> I don't like it for the task. To use I need to import operator, and
> I don't know is it faster or slower than lambda; I suspect it's
> slower but
> I am too lazy to test. Using lambda to get a simple attribute seems
> simpler to me.
lambda's are always slower than the equivalent coded in c:
[worio at domU-12-31-38-00-59-81 frontend]$ python -m 'timeit' 'import
operator; f=operator.attrgetter("open"); import os' 'f(os)'
100000 loops, best of 3: 5.71 usec per loop
[worio at domU-12-31-38-00-59-81 frontend]$ python -m 'timeit' 'f=lambda
x: x.open; import os' 'f(os)'
100000 loops, best of 3: 6.06 usec per loop
More information about the Python-3000