This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: bisect should support descending order
Type: enhancement Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: John Belmonte, remi.lapeyre, rhettinger
Priority: normal Keywords:

Created on 2019-05-08 18:11 by John Belmonte, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg341921 - (view) Author: John Belmonte (John Belmonte) Date: 2019-05-08 18:11
because "list.pop()"

use case: maintain large ordered list and efficiently remove min item

list.pop() is O(1) but yields the max item.  There is no efficient removal of the min item.

list is by far the fastest collection to use with insort().  While deque offers O(1) popleft(), insort() performance with deque is not acceptable.

Lack of descending support in bisect necessitates workarounds such as using negative-valued items, which hurts code readability and moreover assumes that values are numbers.
msg341934 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-05-08 19:50
Sorry, I don't think this is a worthwhile API extension.  The bisect module is primarily about searching for cut points between ranges.  For your use case, consider using blist or one of the many ordered collection recipes on PyPI (for example: http://www.grantjenks.com/docs/sortedcollections/ ).
msg341937 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2019-05-08 20:01
If issue4356 is accepted, I think it may be possible to use `key=lambda e: -e`.
History
Date User Action Args
2022-04-11 14:59:14adminsetgithub: 81038
2019-05-08 20:01:49remi.lapeyresetnosy: + remi.lapeyre
messages: + msg341937
2019-05-08 19:50:08rhettingersetstatus: open -> closed
messages: + msg341934

assignee: rhettinger
resolution: rejected
stage: resolved
2019-05-08 18:28:43xtreaksetnosy: + rhettinger
2019-05-08 18:11:15John Belmontecreate