← Back to Question List
Python Code Walkthrough #50
Each Mid Of A Binary Search
📄 Code
Read carefully — what does this print?1def search(items: list[int], target: int) -> int:2 low: int = 03 high: int = len(items) - 14 while low <= high:5 mid: int = (low + high) // 26 print("mid", mid, items[mid])7 if items[mid] == target:8 return mid9 if items[mid] < target:10 low = mid + 111 else:12 high = mid - 113 return -114print(search([2, 5, 8, 12, 16, 23, 38], 7))