I have python code to find all the possible choices from the list of lists. But when I have a big size list it gives a larger possible dataset. My function is,
def yield_combos(lst):
if not lst:
yield []
else:
for el in lst[0]:
for combo in yield_combos(lst[1:]):
yield [el] + combo
Above code to the input of,
l=[[1,2,3],[4,5,6],[0,2,7]]
output is,
[1, 4, 0]
[1, 4, 2]
[1, 4, 7]
[1, 5, 0]
[1, 5, 2]
[1, 5, 7]
[1, 6, 0]
[1, 6, 2]
[1, 6, 7]
[2, 4, 0]
[2, 4, 2]
[2, 4, 7]
[2, 5, 0]
[2, 5, 2]
[2, 5, 7]
[2, 6, 0]
[2, 6, 2]
[2, 6, 7]
[3, 4, 0]
[3, 4, 2]
[3, 4, 7]
[3, 5, 0]
[3, 5, 2]
[3, 5, 7]
[3, 6, 0]
[3, 6, 2]
[3, 6, 7]
Now I want to reduce the output list with a condition like, all the possible list should include at least one list first item. Then it should remove below item from the list,
[2,5,2]
[2,5,7]
[2,6,2]
[2,6,7]
[3,5,2]
[3,5,7]
[3,6,2]
[3,6,7]
This will help to optimize my algorithm for a large list. How can I do this?