Skip to content

Commit 0795499

Browse files
author
Kcstring
committed
searches: improve linear search type hints
1 parent 791deb4 commit 0795499

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

searches/linear_search.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
python3 linear_search.py
99
"""
1010

11+
from collections.abc import Sequence
1112

12-
def linear_search(sequence: list, target: int) -> int:
13+
14+
def linear_search[T](sequence: Sequence[T], target: T) -> int:
1315
"""A pure Python implementation of a linear search algorithm
1416
1517
:param sequence: a collection with comparable items (sorting is not required for
@@ -33,7 +35,9 @@ def linear_search(sequence: list, target: int) -> int:
3335
return -1
3436

3537

36-
def rec_linear_search(sequence: list, low: int, high: int, target: int) -> int:
38+
def rec_linear_search[T](
39+
sequence: Sequence[T], low: int, high: int, target: T
40+
) -> int:
3741
"""
3842
A pure Python implementation of a recursive linear search algorithm
3943

0 commit comments

Comments
 (0)