#1,排列比如随机抛两个或三个骰子,列出所有的可能:importitertoolsa=range(7)[1:]printlist(itertools.product(a))#一个骰子printlist(itertools.product(a,a))# 两个骰子>>> print list(itertools.product(a, a))
[(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6), (3, 1), (3, 2), (3, 3), (3, 4), (3, 5), (3, 6), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5), (4, 6), (5, 1), (5, 2), (5, 3), (5, 4), (5, 5), (5, 6), (6, 1), (6, 2), (6, 3), (6, 4), (6, 5), (6, 6)]more#**2,组合 **比如随机抛10个女孩中挑3个约会,多少种情况importitertoolsa=range(11)[1:]#没必要是数字~printitertools.combinations(a,3)printlen(itertools.combinations
...
继续阅读
(16)