I have a list of lists as shown below. I want to iterate the list and for each list item with 'yes' at index 1, I want to update index 2 with count of occurrences of 'no' before I get another yes and then add add 1 to it. I don't know how to iterate over a range with a while to stop when I encounter another yes.
I've simplified the data in the Problem and Answer below, however here is the code I was using against the object to try and accomplish.
Problem
fullchart = [
[1, 'yes', 0],
[2, 'no', 0],
[3, 'no', 0],
[4, 'yes', 0],
[5, 'no', 0],
[6, 'no', 0],
[7, 'yes', 0],
[8, 'no', 0],
[9, 'yes', 0]
]
Expected Output
[
[1, 'yes', 3],
[2, 'no', 0],
[3, 'no', 0],
[4, 'yes', 3],
[5, 'no', 0],
[6, 'no', 0],
[7, 'yes', 2],
[8, 'no', 0],
[9, 'yes', 1]
]
Code
end_page = 0
for i in range(len(fullchart)):
end_page = 0
#pprint.pprint(fullchart[i][1])
if fullchart[i][1] == 'yes':
for b in range(i+1, len(fullchart)):
print(b)
if fullchart[i+1][1] == 'no':
end_page += 1
print('printing end_page')
print(end_page)
fullchart[i][3] == end_page
else:
pass