Bisect, is it possible to work with descending sorted lists?

前端 未结 10 708
旧巷少年郎
旧巷少年郎 2020-12-09 15:37

How can I use bisect module on lists that are sorted descending? e.g.

import bisect

x = [1.0,2.0,3.0,4.0] # normal, ascending
bisect.insort(x,2.5)  # -->         


        
10条回答
  •  -上瘾入骨i
    2020-12-09 16:33

    I had the same problem and since when I used ordered list.

    I ended up with solution where I kept original list always in ascending order and just used reversed iterator when I needed to have descending order values.

    This might not work with your problem...

提交回复
热议问题