Dar*_*bes 1 python algorithm binary
在Python中我希望看到一个数字的所有可能组合,但限制为0和1 ...
因此,例如某些循环的结果将是:
0000
0001
0011
0111
1111
1000
and so on.
Run Code Online (Sandbox Code Playgroud)
什么python算法最适合这个?
示例在itertools文档中:
>>> import itertools
>>> for i in itertools.product(range(2), repeat=4):
print(i)
Run Code Online (Sandbox Code Playgroud)