I have a list containing only True
and False
values. I am looking for a pattern when the elements of the list changes from True
to False
or vise versa more than 3 times.
Example (T is used for True
and F for False
for abbreviation):
List = [T, T, T, F, F, F, T, F, T, F, T, T, T, T]
What I want to detect is : [F, T, F, T, F, T]
and its starting index in the original list.
Please note that the pattern is not fixed. It may be [F, T, F, T, F, T]
or [T, F, T, F, T]
.
If you have any idea to accomplish this task efficiently, please let me know.
If fact, I need this detection to be done in real-time. I mean, the List
is being made by getting data from another source (timestamp is 0.5 second). And I need to detect the above mentioned pattern in the List
.
In you are aware how to solve this problem (either real time or not), please let me know.