📜  python代码示例中的二进制搜索

📅  最后修改于: 2022-03-11 14:45:35.125000             🧑  作者: Mango

代码示例6
def binary_search(group, suspect):
  group.sort()
  midpoint = len(group)//2
  while(True):
    if(group[midpoint] == suspect):
      return midpoint
    if(suspect > group[midpoint]):
            group = group[midpoint]
    if(suspect < group[midpoint]):
      group = group[0: midpoint]
    midpoint = (len(group)//2)