python 是否有一些内置函数,通过它我可以生成这样的序列
对于i = 5,0和1有多少种不同的方式可以占据5个位置
00000
00001
00010
00011
00100
.
.
.
.
11111
对于i = 6,0和1有多少种方式可以占据6个位置:
000000
000001
000010
000011
000100
000101
.
.
.
111111
我已经熟悉itertools 排列和组合
,但我无法生成这样的序列。任何帮助将不胜感激。
最佳答案
您可以使用 itertools.product
>>>from itertools import product
>>>list(product([0,1],repeat=5))
关于python - Python中的排列组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32535031/