ID EN
Itertools

product

Python 3.11 🇮🇩 Bahasa Indonesia

Produk kartesius dari input yang dapat diubah.

Syntax

PYTHON
itertools.product(*iterables, repeat=1)

Contoh

Example 1
PYTHON
def product(*args, repeat=1):
     product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
     product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
    pools = [tuple(pool) for pool in args] * repeat
    result = [[]]
    for pool in pools:
        result = [x+[y] for x in result for y in pool]
    for prod in result:
        yield tuple(prod)

See Also

product()