listA = ['000','001','010','011', '100','101','111','110']
To get the above list I usually use the following code. My aim is to get all the possible combinations of 3 numbers where each number can either be 0
or 1
.
listA = list(range(0,222))
listA = [str(x).zfill(3) for x in listA]
listA = [x for x in listA if not x[-3] in [str(z) for z in range(2,10,1)]]
listA = [x for x in listA if not x[-2] in [str(z) for z in range(2,10,1)]]
listA = [x for x in listA if not x[-1] in [str(z) for z in range(2,10,1)]]
This only works if list(range(0,222))
is relatively small, for large range like (0,222222222222)
, listA = list(range(0,222222222222))
returns Memory error
. Is there another way to do this?