[Python-Dev] PEP 326 (quick location possibility)

Raymond Hettinger python at rcn.com
Thu Jan 29 10:24:27 EST 2004


> Indeed, I had a bug within the past few years in a find-the-minimum
search
> loop, using an initial value 10x larger than anything I thought I'd
ever
> see.  A few months later, the inputs in one case happened *all* to be
> larger
> than that, so it returned the bogus initial value as if it were a
sensible
> result.  Hilarity ensued.  There are few enough bugs in my code at
this
> age
> that I take very seriously any principled gimmick that could prevent
> repeating one.  

Alex Martelli had proposed extending the key= idea to min() and max().
The idea is to let those functions completely encapsulate the logic
of searching for minimum and maximum elements:

   bestplayer = min(players, key=attrgetter('points'))

This would work equally well with other objective functions.


Raymond Hettinger


#################################################################
#################################################################
#################################################################
#####
#####
#####
#################################################################
#################################################################
#################################################################



More information about the Python-Dev mailing list