我可以就二进制搜索代码提出建议吗?它陷入无限循环 . 我已经完成了几次代码,但似乎无法发现问题 . 我省略了代码的第一部分,因为它运行良好 . 简而言之,代码的第一部分将一组数据读入名为“bait_dict”的字典列表中 .

import csv

def comparison (input_file, output_file):
    count = 0
    count_in = 0
    count_out = 0
    for line in input_file:
        count += 1
        chrom_file = line[0]
        base_file = int(line[1])
        if chrom_file in bait_dict:
            for value in bait_dict[chrom_file]:
                low = 0
                high = len (bait_dict[chrom_file]) - 1
            while low <= high:
                mid = (low + high)//2
                start, end = bait_dict[chrom_file][mid]
                if base_file < start:
                    high = mid - 1
                elif base_file > end:
                    low = mid + 1
                elif start <= base_file and base_file <= end:
                    count_in += 1  
                    output_file.writerow(line)
                    break
            count_out += 1