enumerate
enumerate[IterableType: Iterable](ref iterable: IterableType, *, start: Int = 0) -> _Enumerate[IterableType.IteratorType[iterable_is_mut, origin_of(iterable), origin_of(iterable)]]
Returns an iterator that yields tuples of the index and the element of the original iterator.
Examples:
var l = ["hey", "hi", "hello"]
for i, elem in enumerate(l):
print(i, elem)
Parameters:
- IterableType (
Iterable): The type of the iterable.
Args:
- iterable (
IterableType): An iterable object (e.g., list, string, etc.). - start (
Int): The starting index for enumeration (default is 0).
Returns:
_Enumerate: An enumerate iterator that yields tuples of (index, element).
enumerate(var iterable: T, *, start: Int = 0) -> _Enumerate[T.IteratorOwnedType]
Returns an iterator that yields tuples of the index and the element of the original iterator, consuming the iterable.
Args:
- iterable (
T): An iterable object to consume and enumerate. - start (
Int): The starting index for enumeration (default is 0).
Returns:
_Enumerate: An enumerate iterator that yields tuples of (index, element).