这被称为笛卡尔积.您可以使用itertools 模块:
itertools
>>> from itertools import product >>> list(product([2,3], repeat=3)) [(2, 2, 2), (2, 2, 3), (2, 3, 2), (2, 3, 3), (3, 2, 2), (3, 2, 3), (3, 3, 2), (3, 3, 3)]