def product(*args, repeat=1):
# product('ABCD', 'xy') > Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) > 000 001 010 011 100 101 110 111
pools = [tuple(pool) for pool in args] * repeat
result = [[]]
for pool in pools:
result = [x+[y] for x in result for y in pool]
for prod in result:
yield tuple(prod)
大部分itertools代码都在文档中。它们也展示了相同或相似的配方https://docs.python.org/3/library/itertools.html?highlight=itertools此处:
现在您已经有了不使用itertools的产品。你可以
相关问题 更多 >
编程相关推荐