from bisect import bisect, insort # Return the index. def in_bisect(sorted_list, target_value): i = bisect(sorted_list, target_value) return i # Return the new list. def insert_by_bisect(sorted_list, target_value): i = insort(sorted_list, target_value) return sorted_list