def insort_right_rev(alist, new_element, low=0, high=None):
"""Similar to bisect.insort_right but for reverse sorted lists
This code is similar to the Python code found in Lib/bisect.py.
We simply change the comparison from 'less than' to 'greater than'.
"""
if low < 0:
raise ValueError('low must be non-negative')
if high is None:
high = len(alist)
while low < high:
middle = (low + high) // 2
if new_element > alist[middle]:
high = middle
else:
low = middle + 1
alist.insert(low, new_element)
评论列表
文章目录