So far I have mylist = list(itertools.product(*a))
The problem with this is that it makes too many tuples. I want it not to make the tuple if the sum of all of tuple is > 4. eg
[(0, 0, 0, 0),
(0, 0, 0, 1),
(0, 0, 0, 2),
(0, 0, 1, 0),
(0, 0, 1, 1),
(0, 0, 1, 2),
(0, 1, 0, 0),
(0, 1, 0, 1),
(0, 1, 0, 2),
(0, 1, 1, 0),
(0, 1, 1, 1),
(0, 1, 1, 2),
(1, 0, 0, 0),
(1, 0, 0, 1),
(1, 0, 0, 2),
(1, 0, 1, 0),
(1, 0, 1, 1),
(1, 0, 1, 2),
(1, 1, 0, 0),
(1, 1, 0, 1),
(1, 1, 0, 2),
(1, 1, 1, 0),
(1, 1, 1, 1),
(1, 1, 1, 2)]
It shouldn't make (1, 1, 1, 2)
as it sums to 5
; while in this example it's only one, in others it will be considerably more.