Skip to content

Instantly share code, notes, and snippets.

@Diapolo10
Last active March 2, 2022 10:50
Show Gist options
  • Save Diapolo10/d2afc3e25af9c4d078f4a741afbfeb3d to your computer and use it in GitHub Desktop.
Save Diapolo10/d2afc3e25af9c4d078f4a741afbfeb3d to your computer and use it in GitHub Desktop.
Python enumerate-function example implementation
from typing import Generator, Iterable, T, Tuple
def my_enumerate(iterable: Iterable[T], start: int=0) -> Generator[Tuple[int, T], None, None]:
"""
Mimics the built-in enumerate-function, accepting any iterable,
and yielding incremented indices and values from it.
"""
idx = start
for value in iterable:
yield idx, value
idx += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment