Skip to content

Commit c389604

Browse files
author
deepshekhardas
committed
fix(searches): handle empty list in sentinel_linear_search
Returns None early for empty sequence instead of incorrectly returning 0 after appending target.
1 parent c0db072 commit c389604

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎searches/sentinel_linear_search.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def sentinel_linear_search(sequence, target):
3131
>>> sentinel_linear_search([0, 5, 7, 10, 15], 6)
3232
3333
"""
34+
if not sequence:
35+
return None
36+
3437
sequence.append(target)
3538

3639
index = 0

0 commit comments

Comments
 (0)