I want to create all possible lists of binary vectors until a specified length, is there a better "pythonic" way to do this?
1
0
11
10
01
00
111
110
101
100
011
010
001
000
[...]
I used a recursive function of incrementing size:
def createAllBinHelper(length):
def createAllBin(thelist, length):
if length == 0:
allpossibilities.append(thelist)
else:
createAllBin(thelist+'1', length-1)
createAllBin(thelist+'0', length-1)
allpossibilities = []
for i in range(1,length):
createAllBin('', i)
return allpossibilities