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 :: number of rows or columns in numpy ndarray python 
Python :: train test split pandas 
Python :: 2 d array in python with zeroes 
Python :: how to save model to a file python 
Python :: print the heat map python 
Python :: django model query add annotation field to show duplicate count 
Python :: pythons os module choose random file 
Python :: count how many vowels in a string python 
Python :: renpy scene vs show 
Python :: How do I start a DataFrame index from 1? 
Python :: DataFrame.plot.line() method: | dataframe line plot 
Python :: pandas filter non nan 
Python :: an array of dates python 
Python :: repeat 10 times python 
Python :: python sort string 
Python :: convert string to operator python 
Python :: how to get total number of rows in listbox tkinter 
Python :: firebase-admin python 
Python :: get all indices of a value in list python 
Python :: open mat file in python 
Python :: how to rearrange list in python 
Python :: python request post with json with headers 
Python :: count number of rows pandas condition 
Python :: how to say hello with name in python 
Python :: pandas drop column by index range 
Python :: github black badge 
Python :: pandas row number by group 
Python :: Select rows from a DataFrame based on column values? 
Python :: kaaba python tutorial 
Python :: logout in discord.py 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =