Skip to content

Instantly share code, notes, and snippets.

@liuzheng1990
Created June 29, 2021 06:38
Show Gist options
  • Save liuzheng1990/73a77a4871ad9c83a7e561da5ec92fcc to your computer and use it in GitHub Desktop.
Save liuzheng1990/73a77a4871ad9c83a7e561da5ec92fcc to your computer and use it in GitHub Desktop.
Example of Python type variables
from typing import Iterable, TypeVar
T = TypeVar('T')
def linear_search(l: Iterable[T],
target: T,
upper_limit=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