Skip to content

Commit 28fff0f

Browse files
committed
Fix: Improve: handle empty sequence case in linear_search
1 parent 2ffa363 commit 28fff0f

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

searches/linear_search.py

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

11-
12-
def linear_search(sequence: list, target: int) -> int:
13-
"""... existing docstring ..."""
14-
15-
if not sequence:
16-
return -1
17-
18-
1911
def linear_search(sequence: list, target: int) -> int:
2012
"""A pure Python implementation of a linear search algorithm
2113
@@ -29,6 +21,9 @@ def linear_search(sequence: list, target: int) -> int:
2921
>>> linear_search([0, 5, 7, 10, 15], 6)
3022
-1
3123
"""
24+
if not sequence:
25+
return -1
26+
3227
for index, item in enumerate(sequence):
3328
if item == target:
3429
return index

0 commit comments

Comments
 (0)