I have two lists in python.
list1 = ['A', 'B']
list2 = [True, False]
list1 has been simplified in the real world it will be more than 2 elements. list 2 will only be true or false.
I'd like to generate the following output, given 2 elements in list1:
output=[
[['A', True], ['B', True]],
[['A', False], ['B', True]],
[['A', True], ['B', False]],
[['A', False], ['B', False]]]
I'd like the algorithm to be able to support the scenario with more than 2 elements in list1.
Here is an example with 3 elements in list1:
list1 = ['A', 'B', 'C']
list2 = [True, False]
output=[
[['A', True], ['B', True], ['C', True]],
[['A', True], ['B', True], ['C', False]],
[['A', True], ['B', False], ['C', True]],
[['A', False], ['B', True], ['C', True]],
[['A', False, ['B', False], ['C', True]],
[['A', True], ['B', False, ['C', False]],
[['A', False], ['B', True], ['C', False]],
[['A', False], ['B', False], ['C', False]]
]
The following gets me close but not quite there.
[zip(x, list2) for x in it.permutations(list1, len(list2))]
I know I need to do something using itertools but cannot wrap my head around it. Any advice would be greatly appreciated.