Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions searches/binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
python3 binary_search.py
"""

from __future__ import annotations

import bisect
from itertools import pairwise


def bisect_left(
Expand Down Expand Up @@ -198,7 +197,7 @@ def binary_search(sorted_collection: list[int], item: int) -> int:
>>> binary_search([0, 5, 7, 10, 15], 6)
-1
"""
if list(sorted_collection) != sorted(sorted_collection):
if any(a > b for a, b in pairwise(sorted_collection)):
raise ValueError("sorted_collection must be sorted in ascending order")
left = 0
right = len(sorted_collection) - 1
Expand Down