How do I create a new list containing only the beginning index number of where the segment of True elements consecutively repeat?
main_list = [True, True, False, False, True, True, True, True, True, False]
The expected answer should be:
true_index = [0,4] #first repeating True starts at index 0 from main_list and the second repeating True starts at index 4 from main_list
If given a list like:
l = [True,False,False]
Expected answer would be:
index_list = [0]
I need a simple code that does not require the use of numpy or groupby. I tried dividing the main_list into sublists first containing groups of the repeating True elements, however also struggled without using numpy or groupby.
See Question&Answers more detail:os