I have this python program that I would like to filter the array result’s where the sum of array results == 2 and ‘A’ in array results must appear at least once in that array.
from itertools import product
d = {"A": 0, "B": 2, "C": 0}
for arr in product(d, repeat=2):
print(arr, f"The sum is: {sum(d[i] for i in arr)}")
Results
('A', 'A') The sum is: 0
('A', 'B') The sum is: 2
('A', 'C') The sum is: 0
('B', 'A') The sum is: 2
('B', 'B') The sum is: 4
('B', 'C') The sum is: 2
('C', 'A') The sum is: 0
('C', 'B') The sum is: 2
('C', 'C') The sum is: 0
Instead I want the code that display the following results;
('A', 'B') The sum is: 2
('B', 'A') The sum is: 2