Background
I have a nested list. In each sublist are four 1s or 0s identifying survival (living or dead) for a specimen. When a specimen is born they go from 0 to 1, a specimen death goes from 1 to 0.
Problem
Because specimens can't come back from the dead I need to identify where a specimen was 1, went to 0 at least once and then back to 1.
Current Solution
Because the list always has exactly 4 entries (each representing a year where their living or dead status was observed), I've hard-coded a solution based on comparing the entries with if/else but it is very inelegant and would require exponentially more if/else statements if the data is collected another year.
Is there a better way?
Short, Self Contained, Compilable Example
#Sample list
my_list = [[1,1,1,1], #no issue, survived 4 years
[1,1,0,1], #data quality issue, died and then born again
[1,0,0,1], #data quality issue, died and then born again
[0,0,0,1], #no issue, born in 4th year
[1,0,0,0]] #no issue, died after 1st year
#Iterate through the list
for each in my_list:
if ((each[0] == 1) and (each[1] == 1)) and (each[2] == 0) and (each[3] == 1):
print(str(each) + ' has data quality issues')
if ((each[0] == 1) and (each[1] == 0)) and (each[2] == 1):
print(str(each) + ' has data quality issues')
if ((each[1] == 0) and (each[2] == 0)) and (each[3] == 1):
if each[0] == 0:
pass #do nothing
else:
print(str(each) + ' has data quality issues')
Output
[1, 1, 0, 1] has data quality issues
[1, 0, 0, 1] has data quality issues