I have a list of lists of boolean values. I’m trying to return a list of indexes where all values in the same positions are only False. So in the example below, position 3
and 4
of each inner list are False, so return [3,4]
.
Some assumptions to keep in mind, the list of lists could contain X number of lists, so can’t rely on just three, it could be 50. Also, the inner lists will always have equal lengths, so no worrying about different-sized lists, but they could be longer than 6 like in the example I gave. So the solution must work for dynamic sizes/lengths.
list1 = [True, True, True, False, False, False]
list2 = [True, True, False, False, False, False]
list3 = [True, True, True, False, False, True]
list_of_lists = [list1, list2, list3]
result_list_of_all_false_indexes = []
# Pseudo code
# Look in position 0 of each list in the list of lists. If they're all false
# result_list_of_all_false_indexes.append(index)
# Look in position 1 of each list in the list of lists. If they're all false
# result_list_of_all_false_indexes.append(index)
# continue for entire length of inner lists
assert result_list_of_all_false_indexes == [3,4], "Try again..."
>Solution :
With some help from numpy, we can check your conditions by axis:
import numpy as np
results = np.where(~np.any(list_of_lists, axis=0))[0].tolist()
# Output:
[3, 4]