Last active
March 2, 2022 10:50
-
-
Save Diapolo10/d2afc3e25af9c4d078f4a741afbfeb3d to your computer and use it in GitHub Desktop.
Python enumerate-function example implementation
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 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