Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

cartesian product of a list python

import itertools

somelists = [
   [1, 2, 3],
   ['a', 'b'],
   [4, 5]
]
for element in itertools.product(*somelists):
    print(element)
Comment

python cartesian product

# initialize lists
listA = [1, 4, 6, 7]
listB = [1, 3]
  
# Construct Cartesian Product Tuple list
# using list comprehension
res = [(a, b) for a in listA for b in listB]
  
# printing result
print("The Cartesian Product is : " + str(res))
Comment

PREVIOUS NEXT
Code Example
Python :: python for loop max iterations 
Python :: plt axis label font size 
Python :: how to create a loop in python turtle 
Python :: python csv reader skip header 
Python :: pd add column with zeros 
Python :: author nextcord interactions 
Python :: how to draw in pygame 
Python :: Local to ISO 8601 with TimeZone information (Python 3): 
Python :: update python mac 
Python :: pytorch use multiple gpu 
Python :: telnet python 
Python :: Creating virtual environments 
Python :: python trick big numbers visualisation 
Python :: django modelform style 
Python :: tkinter hello world 
Python :: filter dataframe 
Python :: AdaBoost in Python 
Python :: location of last row dataframe 
Python :: python get methods of object 
Python :: python lexicographical comparison 
Python :: pandas iterate over a series 
Python :: django staff_member_required decorator 
Python :: python typeddict 
Python :: load saved model tensorflow 
Python :: discord.py check if message has certain reaction 
Python :: pandas series to numpy array 
Python :: how to create a role and give it to the author discord.py 
Python :: python get nearest value in list 
Python :: sort df by column 
Python :: python __version__ 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =