[issue4356] Add "key" argument to "bisect" module functions

Mark Dickinson report at bugs.python.org
Thu Nov 20 11:11:10 CET 2008


Mark Dickinson <dickinsm at gmail.com> added the comment:

What about cases where performance is unimportant, or where the key 
function is fast (e.g. an attribute access)?  Then something like

bisect(a, x, key=attrgetter('size'))

is easy to write and read.  Mightn't this be considered good design,
from some perspectives?

Another thought:  if your list is a list of user-defined objects then a 
natural way to do the 'decorate' step of DSU might be to add a 'key' 
attribute to each object, rather than the usual method of constructing 
pairs.  (This has the advantage that you might not have to bother with the 
'undecorate' step.)  With a key argument, bisect could make use of this 
technique too.

Disclaimer: I haven't personally had any need for a key argument on 
bisect, so all this is hypothetical.  That's why I'm asking for real use-
cases.

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4356>
_______________________________________


More information about the Python-bugs-list mailing list