python:我如何创建以元组形式为 A 和 B 中的整数生成所有可能组合的东西

python: how can I create something which generates all possible combinations in a form of tuples for integers from A and B

问题:

# 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

-我正在考虑使用 for 循环,但似乎无法让它工作。

使用itertools.product,如下代码:

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

为了简单起见,您可以使用:

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

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