Re: why not bisect options?



[Robert Bossy]
I thought it would be useful if insort and consorts* could accept the
same options than list.sort, especially key and cmp.

If you're going to do many insertions or searches, wouldn't it be
*much* more efficient to store your keys in a separate array?

The sort() function guarantees that it calls the key function exactly
once for each member of the list. With and bisect/insort, successive
searches can call the key function over and over again with the same
value.


Raymond



.



Relevant Pages

  • Re: why not bisect options?
    ... If you're going to do many insertions or searches, ... *much* more efficient to store your keys in a separate array? ... The sort() function guarantees that it calls the key function exactly ...
    (comp.lang.python)
  • Re: why not bisect options?
    ... Selon Raymond Hettinger: ... same options than list.sort, especially key and cmp. ... If you're going to do many insertions or searches, ... The sortfunction guarantees that it calls the key function exactly ...
    (comp.lang.python)
  • Re: Q: sorts key and cmp parameters
    ... When I learned that cmp was being dropped, ... Occasionally I come across sorting problems where it isn't obvious how to ... write the key function, but I've never come across one where it wasn't ... Here's one thing I've sometimes wanted to do: sort multiple lists at ...
    (comp.lang.python)
  • Re: python 3: sorting with a comparison function
    ... the 'cmp' argument seems to be gone. ... Terry Reedy schrieb: ... Calling the key function n times has to be faster than calling a compare ... solutions of the sorting problem. ...
    (comp.lang.python)
  • Re: Q: sorts key and cmp parameters
    ... are mathematically equivalent (you could always do a compare ... sort first, record the order produced, and assign the position ... then having to convert to a key function ... simpler to write and faster to run than a cmp function approach. ...
    (comp.lang.python)