Mojo function
product
product[IterableTypeA: Iterable, IterableTypeB: Iterable](ref iterable_a: IterableTypeA, ref iterable_b: IterableTypeB) -> _Product2[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 outer product of the iterables.
Examples:
var l = ["hey", "hi", "hello"]
var l2 = [10, 20, 30]
for a, b in product(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:
_Product2: A product iterator that yields outer product tuples of elements from both
iterables.
product[IterableTypeA: Iterable, IterableTypeB: Iterable, IterableTypeC: Iterable](ref iterable_a: IterableTypeA, ref iterable_b: IterableTypeB, ref iterable_c: IterableTypeC) -> _Product3[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 outer product of three iterables.
Examples:
var l1 = [1, 2]
var l2 = [3, 4]
var l3 = [5, 6]
for a, b, c in product(l1, 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:
_Product3: A product iterator that yields outer product tuples of elements from all
three iterables.
product[IterableTypeA: Iterable, IterableTypeB: Iterable, IterableTypeC: Iterable, IterableTypeD: Iterable](ref iterable_a: IterableTypeA, ref iterable_b: IterableTypeB, ref iterable_c: IterableTypeC, ref iterable_d: IterableTypeD) -> _Product4[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 outer product of four iterables.
Examples:
var l1 = [1, 2]
var l2 = [3, 4]
var l3 = [5, 6]
var l4 = [7, 8]
for a, b, c, d in product(l1, 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:
_Product4: A product iterator that yields outer product tuples of elements from all
four iterables.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!