Answers for "python cartesian product"

1

cartesian product of a list python

import itertools

somelists = [
   [1, 2, 3],
   ['a', 'b'],
   [4, 5]
]
for element in itertools.product(*somelists):
    print(element)
Posted by: Guest on July-11-2021
0

pandas cartesian product

a = [1, 2, 3]
b = ["a", "b", "c"]

index = pd.MultiIndex.from_product([a, b], names = ["a", "b"])

pd.DataFrame(index = index).reset_index()
Posted by: Guest on October-10-2020
0

python list comprehension cartesian product

[ (x, y) for x in xs for y in ys ]
Posted by: Guest on December-17-2020

Python Answers by Framework

Browse Popular Code Answers by Language