Skip to main content

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?