现在的需求是,有若干个List,假设2个:
[1, 3, 5]
[4, 6]
我们要输出(1, 4), (1, 6), (3, 4), (3, 6), (5, 4), (5, 6)
Python中直接提供了笛卡尔乘积,很给力:
a = [1, 3, 5]
b = [4, 6]
import itertools
for x in itertools.product(a, b):
print x
(1, 4)
(1, 6)
(3, 4)
(3, 6)
([......]