Created
June 29, 2021 13:54
-
-
Save liuzheng1990/1e8f521379034fe699757cc9a496c8ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Iterable, TypeVar, Optional | |
T = TypeVar('T') | |
def linear_search(l: Iterable[T], | |
target: T, | |
upper_limit: Optional[int]=None) -> bool: | |
for idx, item in enumerate(l): | |
if item == target: | |
return True | |
if upper_limit is not None and idx >= upper_limit: | |
break | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment