From 2d0f5141acad4adda401dc0065175f85b1d62a93 Mon Sep 17 00:00:00 2001 From: Mister Lobster Date: Sun, 3 May 2026 07:33:44 -0400 Subject: [PATCH] refactor: improve type hints in linear_search.py - Changed sequence parameter from list to list[Any] for better type specificity - Changed target parameter from int to Any for better flexibility - Added typing import for Any type - This allows the functions to work with any comparable types, not just integers - All existing doctests pass - Type checking with mypy passes --- searches/linear_search.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/searches/linear_search.py b/searches/linear_search.py index 8adb4a7015f0..b8d7d0a58094 100644 --- a/searches/linear_search.py +++ b/searches/linear_search.py @@ -8,8 +8,10 @@ python3 linear_search.py """ +from typing import Any -def linear_search(sequence: list, target: int) -> int: + +def linear_search(sequence: list[Any], target: Any) -> int: """A pure Python implementation of a linear search algorithm :param sequence: a collection with comparable items (sorting is not required for @@ -33,7 +35,7 @@ def linear_search(sequence: list, target: int) -> int: return -1 -def rec_linear_search(sequence: list, low: int, high: int, target: int) -> int: +def rec_linear_search(sequence: list[Any], low: int, high: int, target: Any) -> int: """ A pure Python implementation of a recursive linear search algorithm