def sequential_search(lis, key):
    length = len(lis)
    for i in range(length):
        if lis[i] == key:
            return i
    return False

LIST = [1, 5, 8, 123, 22, 54, 7, 99, 300, 222]
result = sequential_search(LIST, 123)
print(result)

如果查找到123就会打印出123 的位置索引,否则显示false

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2021-12-10
  • 2022-12-23
  • 2021-12-06
  • 2021-08-07
  • 2022-12-23
猜你喜欢
  • 2022-02-23
  • 2022-03-05
  • 2022-12-23
  • 2022-12-23
  • 2021-09-10
  • 2021-11-21
  • 2022-12-23
相关资源
相似解决方案