Get all possible combinations in 3 different sets


Selkuk

I'm trying to write a python program that iterates through a list of all possible numbers for 3 different sets and prints out all possible numbers. The numerical range is given at the bottom. No 2 sets of numbers should be repeated, each order should be different from each other. Please see the expected output for the expected output of the code. I would like the code below to return for i in set1: after running out of indices for p in set3:so that all possible combinations can be printed.

set1 = [i for i in range(2,11)]
set2 = [i for i in range(1,5)]
set3 = [i for i in range(1,5)]

for i in set1:
    for k in set2:
        for p in set3:
            print(set1[i], set2[k], set3[p])

Setting 1: Numbers from 2 to 11

Group 2: Numbers from 1 to 5

Setting 3: Numbers from 1 to 5

Expected results (Group 1, Group 2, Group 3):

(2,1,1),(2,2,1),(2,3,1),(2,4,1),(2,1,2),(2,1,3),(2 ,1,4)

(2,2,2),(2,2,3),(2,2,4),(1,2,1),(3,2,1),(4,2,1),(5 ,2,1,),(6,2,1),(7,2,1),(8,2,1),(9,2,1),(10,2,1)

Viraat Das

you can use ititertools.product

import itertools
list_set = [set1, set2, set3]
for element in itertools.product(*list_set):
  print(element)

Related


Get all possible combinations in 3 different sets

Selkuk I'm trying to write a python program that iterates over a list of all possible numbers for 3 different sets and prints out all possible numbers. The numerical range is given at the bottom. No 2 sets of numbers should be repeated, each order should be di

Get all possible combinations in 3 different sets

Selkuk I'm trying to write a python program that iterates over a list of all possible numbers for 3 different sets and prints out all possible numbers. The numerical range is given at the bottom. No 2 sets of numbers should be repeated, each order should be di

Get all possible combinations in 3 different sets

Selkuk I'm trying to write a python program that iterates through a list of all possible numbers for 3 different sets and prints out all possible numbers. The numerical range is given at the bottom. No 2 sets of numbers should be repeated, each order should be

Get all possible combinations in 3 different sets

Selkuk I'm trying to write a python program that iterates through a list of all possible numbers for 3 different sets and prints out all possible numbers. The numerical range is given at the bottom. No 2 sets of numbers should be repeated, each order should be

All possible combinations of sets in Matlab

username I'm trying to find all possible combinations of a set, but the order of the elements is also important to my problem. For this set set={A, B, C}, for example, the possible subsets are subsets={A},{B},{C},{A,B},{A,C},{B,A},{B,C},{C,A},{C,B},{A,B,C},{A,

All possible combinations of sets in Matlab

username I'm trying to find all possible combinations of a set, but the order of the elements is also important to my problem. For this set set={A, B, C}, for example, the possible subsets are subsets={A},{B},{C},{A,B},{A,C},{B,A},{B,C},{C,A},{C,B},{A,B,C},{A,

All possible combinations of sets in Matlab

username I'm trying to find all possible combinations of a set, but the order of the elements is also important to my problem. For this set set={A, B, C}, for example, the possible subsets are subsets={A},{B},{C},{A,B},{A,C},{B,A},{B,C},{C,A},{C,B},{A,B,C},{A,

Create all possible combinations from multiple sets

Merlin Anne My knowledge of math is limited, so please excuse the terms if I'm mistaken. I need to create all possible combinations from multiple sets with at least one item from that set. - SetA: [1, 2, 3, 4, 5, 6, 7] - SetB: [a, b, c, d] - SetC: [!, @,

Create all possible combinations from multiple sets

Merlin Anne My knowledge of math is limited, so please excuse the terms if I'm mistaken. I need to create all possible combinations from multiple sets with at least one item from that set. - SetA: [1, 2, 3, 4, 5, 6, 7] - SetB: [a, b, c, d] - SetC: [!, @,

Create all possible combinations from multiple sets

Merlin Anne My knowledge of math is limited, so please excuse the terms if I'm mistaken. I need to create all possible combinations from multiple sets with at least one item from that set. - SetA: [1, 2, 3, 4, 5, 6, 7] - SetB: [a, b, c, d] - SetC: [!, @,

Create all possible combinations from multiple sets

Merlin Anne My knowledge of math is limited, so please excuse the terms if I'm mistaken. I need to create all possible combinations from multiple sets with at least one item from that set. - SetA: [1, 2, 3, 4, 5, 6, 7] - SetB: [a, b, c, d] - SetC: [!, @,

Create all possible combinations from multiple sets

Merlin Anne My knowledge of math is limited, so please excuse the terms if I'm mistaken. I need to create all possible combinations from multiple sets with at least one item from that set. - SetA: [1, 2, 3, 4, 5, 6, 7] - SetB: [a, b, c, d] - SetC: [!, @,

Create all possible combinations from multiple sets

Merlin Anne My knowledge of math is limited, so please excuse the terms if I'm mistaken. I need to create all possible combinations from multiple sets with at least one item from that set. - SetA: [1, 2, 3, 4, 5, 6, 7] - SetB: [a, b, c, d] - SetC: [!, @,

Create all possible combinations from multiple sets

Merlin Anne My knowledge of math is limited, so please excuse the terms if I'm mistaken. I need to create all possible combinations from multiple sets with at least one item from that set. - SetA: [1, 2, 3, 4, 5, 6, 7] - SetB: [a, b, c, d] - SetC: [!, @,

How to get all possible combinations of two different lists?

mimosa I'm having a lot of trouble understanding my problem: I have 2 lists: from = ['A', 'B', 'C'] to = ['D', 'E', 'F'] I need to produce a matrix combining each list from one list to another, for example: final = [[['A', 'D'], ['B', 'E'], ['C', 'F']],

Get all possible combinations from 3 categories in MySQL

Erik Andershed I have 3 categories (cate1, cate2, cate3) and there are 14 rows in the database. I like to get all possible combinations. database: id category 1 cate1 2 cate2 3 cate3 6 cate1 7 cate2 8 cate3 9 cate1 10 cate2 11 cat

Get all possible combinations of elements

sa555 How would you get all possible combinations of 2 elements in an array? E.g: [ 1, 2, 3, 4 ] becomes [ [1, 2], [1, 3], [1, 4], [2, 1], [2, 3], [2, 4], [3, 1], [3, 2], [3, 4], [4, 1], [4

Get all possible combinations of elements

sa555 How would you get all possible combinations of 2 elements in an array? E.g: [ 1, 2, 3, 4 ] becomes [ [1, 2], [1, 3], [1, 4], [2, 1], [2, 3], [2, 4], [3, 1], [3, 2], [3, 4], [4, 1], [4