Skip to main content

Mojo function

zip

zip[IterableTypeA: Iterable, IterableTypeB: Iterable](ref iterable_a: IterableTypeA, ref iterable_b: IterableTypeB) -> _Zip2[IterableTypeA.IteratorType[iterable_a_is_mut, iterable_a_is_origin], IterableTypeB.IteratorType[iterable_b_is_mut, iterable_b_is_origin]]

Returns an iterator that yields tuples of the elements of the original iterables.

Examples:

var l = ["hey", "hi", "hello"]
var l2 = [10, 20, 30]
for a, b in zip(l, l2):
    print(a, b)

Parameters:

  • IterableTypeA (Iterable): The type of the first iterable.
  • IterableTypeB (Iterable): The type of the second iterable.

Args:

  • iterable_a (IterableTypeA): The first iterable.
  • iterable_b (IterableTypeB): The second iterable.

Returns:

_Zip2: A zip iterator that yields tuples of elements from both iterables.

zip[IterableTypeA: Iterable, IterableTypeB: Iterable, IterableTypeC: Iterable](ref iterable_a: IterableTypeA, ref iterable_b: IterableTypeB, ref iterable_c: IterableTypeC) -> _Zip3[IterableTypeA.IteratorType[iterable_a_is_mut, iterable_a_is_origin], IterableTypeB.IteratorType[iterable_b_is_mut, iterable_b_is_origin], IterableTypeC.IteratorType[iterable_c_is_mut, iterable_c_is_origin]]

Returns an iterator that yields tuples of the elements of the original iterables.

Examples:

var l = ["hey", "hi", "hello"]
var l2 = [10, 20, 30]
var l3 = [100, 200, 300]
for a, b, c in zip(l, l2, l3):
    print(a, b, c)

Parameters:

  • IterableTypeA (Iterable): The type of the first iterable.
  • IterableTypeB (Iterable): The type of the second iterable.
  • IterableTypeC (Iterable): The type of the third iterable.

Args:

  • iterable_a (IterableTypeA): The first iterable.
  • iterable_b (IterableTypeB): The second iterable.
  • iterable_c (IterableTypeC): The third iterable.

Returns:

_Zip3: A zip iterator that yields tuples of elements from all three iterables.

zip[IterableTypeA: Iterable, IterableTypeB: Iterable, IterableTypeC: Iterable, IterableTypeD: Iterable](ref iterable_a: IterableTypeA, ref iterable_b: IterableTypeB, ref iterable_c: IterableTypeC, ref iterable_d: IterableTypeD) -> _Zip4[IterableTypeA.IteratorType[iterable_a_is_mut, iterable_a_is_origin], IterableTypeB.IteratorType[iterable_b_is_mut, iterable_b_is_origin], IterableTypeC.IteratorType[iterable_c_is_mut, iterable_c_is_origin], IterableTypeD.IteratorType[iterable_d_is_mut, iterable_d_is_origin]]

Returns an iterator that yields tuples of the elements of the original iterables.

Examples:

var l = ["hey", "hi", "hello"]
var l2 = [10, 20, 30]
var l3 = [100, 200, 300]
var l4 = [1000, 2000, 3000]
for a, b, c, d in zip(l, l2, l3, l4):
    print(a, b, c, d)

Parameters:

  • IterableTypeA (Iterable): The type of the first iterable.
  • IterableTypeB (Iterable): The type of the second iterable.
  • IterableTypeC (Iterable): The type of the third iterable.
  • IterableTypeD (Iterable): The type of the fourth iterable.

Args:

  • iterable_a (IterableTypeA): The first iterable.
  • iterable_b (IterableTypeB): The second iterable.
  • iterable_c (IterableTypeC): The third iterable.
  • iterable_d (IterableTypeD): The fourth iterable.

Returns:

_Zip4: A zip iterator that yields tuples of elements from all four iterables.

Was this page helpful?