你是对的,有更好的方法来做这件事。您只需使用
product
功能来自
itertools
这完全等同于你要做的。这个
docs on it are here
.
这很简单:
>>> from itertools import product
>>> outcomes = list(product(range(2), repeat=16))
>>> print(len(outcomes))
65536
>>> print(outcomes[0])
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
>>> print(outcomes[10000])
(0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0)
你会注意到这并没有给你
[0, 1]
你所期待的对,但很明显,因为每场比赛只有两队,只要把每个位置显示的数字作为第一队的得分,你就可以推断出另一队的得分与此相反。