Mojo function
enumerate
enumerate[IterableType: Iterable](ref iterable: IterableType, *, start: Int = 0) -> _Enumerate[IterableType.IteratorType[iterable_is_mut, iterable_is_origin]]
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)
.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!