Answers for "python product"

1

python product

#from itertools import product


def product(*args, **kwds):
    # 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 = map(tuple, args) * kwds.get('repeat', 1)
    result = [[]]
    for pool in pools:
        result = [x+[y] for x in result for y in pool]
    for prod in result:
        yield tuple(prod)
Posted by: Guest on July-05-2020
0

python product

from itertools import product

if __name__ == "__main__": 
    arr1 = [1, 2, 3]
    arr2 = [5, 6, 7]
    print( list(product(arr1, arr2)) )

Output
[(1, 5), (1, 6), (1, 7), (2, 5), (2, 6), (2, 7), (3, 5), (3, 6), (3, 7)]
Posted by: Guest on August-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language