Skip to content

Commit fc2943d

Browse files
Sync binary-search with the updated tutorial (#943)
* 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 <noreply@anthropic.com> * 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. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5093d33 commit fc2943d

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

‎binary-search/download_imdb.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ def main():
2222
with open("names.txt", "w", encoding="utf-8") as destination:
2323
destination.writelines(names())
2424

25-
with (
26-
open("names.txt", encoding="utf-8") as source,
27-
open("sorted_names.txt", "w", encoding="utf-8") as destination,
28-
):
29-
destination.writelines(sorted(source.readlines()))
25+
with open("names.txt", encoding="utf-8") as source:
26+
with open("sorted_names.txt", "w", encoding="utf-8") as destination:
27+
destination.writelines(sorted(source.readlines()))
3028

3129
print('Created "names.txt" and "sorted_names.txt"')
3230

‎binary-search/search/binary.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def find_all_indices(
6868
left = find_leftmost_index(elements, value, key)
6969
right = find_rightmost_index(elements, value, key)
7070

71-
if left and right:
71+
if left is not None and right is not None:
7272
return set(range(left, right + 1))
7373

7474
return set()

0 commit comments

Comments
 (0)