From 802305db441be0d30812c6a1fccb445a67315cfc Mon Sep 17 00:00:00 2001 From: Real Python Bot <42617967+realpython-bot@users.noreply.github.com> Date: Fri, 13 Nov 2026 06:12:44 +0000 Subject: [PATCH 1/2] Sync binary-search with the maintenance update of How to Do a Binary Search in Python find_all_indices() tested the leftmost and rightmost indices for truthiness, so a match at index 0 returned an empty set. Compare them against None instead, matching the updated tutorial. Co-Authored-By: Claude Opus 5.5 --- binary-search/search/binary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binary-search/search/binary.py b/binary-search/search/binary.py index 0dd6a2d80c..3c32dad0ee 100644 --- a/binary-search/search/binary.py +++ b/binary-search/search/binary.py @@ -68,7 +68,7 @@ def find_all_indices( left = find_leftmost_index(elements, value, key) right = find_rightmost_index(elements, value, key) - if left and right: + if left is not None and right is not None: return set(range(left, right + 1)) return set() From 4855ddbdf0e867cd5f0386c89a5a6d4856c85685 Mon Sep 17 00:00:00 2001 From: realpython-bot <42617967+realpython-bot@users.noreply.github.com> Date: Fri, 13 Nov 2026 06:33:40 +0000 Subject: [PATCH 2/2] Keep download_imdb.py runnable on Python 3.7+ The tutorial and benchmark.py state a Python 3.7 floor, but the parenthesized context managers in download_imdb.py need 3.9. Nested with statements restore the stated floor (vermin: 3.7) without changing behavior. --- binary-search/download_imdb.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/binary-search/download_imdb.py b/binary-search/download_imdb.py index 45a97f4171..e572681b7a 100644 --- a/binary-search/download_imdb.py +++ b/binary-search/download_imdb.py @@ -22,11 +22,9 @@ def main(): with open("names.txt", "w", encoding="utf-8") as destination: destination.writelines(names()) - with ( - open("names.txt", encoding="utf-8") as source, - open("sorted_names.txt", "w", encoding="utf-8") as destination, - ): - destination.writelines(sorted(source.readlines())) + with open("names.txt", encoding="utf-8") as source: + with open("sorted_names.txt", "w", encoding="utf-8") as destination: + destination.writelines(sorted(source.readlines())) print('Created "names.txt" and "sorted_names.txt"')