with open('data') as f:
    lines = [line.strip().split() for line in f]
combinations = {}
for combination in lines[1:]:
    key = ', '.join([lines[0][i] for i in range(len(combination)) if 
        combination[i] != '0'])
combinations[key] = combinations.setdefault(key, 0) + 1
for key, value in combinations.items():
    pass
Computing the combinations for presence or absence of a factor in a table