Question:

# Let A= {m | m is an integer satisfying 0 < m < 13} and 
# B = {n | n is an integer satisfying 7 < n < 23}. 

# I'm trying to generate all possible combinations of (A,B).
For example:

A= (1,2,3,4,5,6,7)
B =(7,8,9,10,11...)

Combination = (1,7),(1,8)(1,9)....(2,7),(2,8),(2,9).... and so forth

-I was thinking of using a for loop but could not seem to manage to get it working.

2

There are 2 answers

0
Pixel_teK On BEST ANSWER

For the sake of simplicity you could just use :

for a in A:
  for b in B:
    print((a,b,))

or

combinations = [(a,b,) for a in A for b in B]
0
Seth On

Use itertools.product, as in the below code:

import itertools
out = itertools.product(A, B)