itertools中的product的用法

看代码及结果

>>> import itertools
>>> a = range(3)
>>> b = range(4,8)
>>> c = itertools.product(a,b)
>>> c
<itertools.product object at 0x108cf3240>
>>> d = [x for x in c]
>>> d
[(0, 4), (0, 5), (0, 6), (0, 7), (1, 4), (1, 5), (1, 6), (1, 7), (2, 4), (2, 5), (2, 6), (2, 7)]

可以看出来,相当于是一个笛卡尔积,这在配对的时候用着非常方便.