I generated a list of binary numbers in python with itertools, of which I want to convert all the 1 to 'ALL' and all the 0 to correspond to the index of the attribs list, where the attribs list is [1, 2], with the measure value 10 appended at the end of each list.
In essence, the list of binary numbers is
[(0, 0), (0, 1), (1, 0), (1, 1)]
I want to convert them to
[(1, 2), (1, 'ALL'), ('ALL', 2), ('ALL', 'ALL')]
So that these will be a form of combinations for the list [1,2].
The final lists when printed should look like these:
[1, 2, 10]
[1, 'ALL', 10]
['ALL', 2, 10]
['ALL', 'ALL', 10]
However, I'm currently getting the following:
[2, 2, 10]
[2, 'ALL', 10]
['ALL', 2, 10]
['ALL', 'ALL', 10]
What am I doing wrong?
import itertools as it
measure = 10
attribs = [1, 2]
# generate binary table based on number of columns
outs = [i for i in it.product(range(2), repeat=(len(attribs)))]
print(outs)
for line in outs:
line = list(line)
# replace binary of 1 or 0 with 'ALL' or value from input
for index, item in enumerate(line):
print("index of line: " + str(index) + " with value: " + str(item))
if (item == 1):
line[index] = 'ALL'
elif (item == 0):
for i in range(len(attribs)):
print("assigning element at line index " + str(index) + " to index of attribs: " + str(i) + " with value: " + str(attribs[i]))
line[index] = attribs[i]
line.append(measure)
print(line)