Let's say I have a list like:
a = ['no', 'no', 'no', 'yes', 'no', 'yes', 'no']
Here I want to delete everyone 'no'that is preceded by everything'yes' . Therefore, my resulting list should look like :
['no', 'no', 'yes', 'yes', 'no']
I found that to remove an item from the list by its value, we can use list.remove(..)as:
a = ['no', 'no', 'no', 'yes', 'no', 'yes', 'no']
a.remove('no')
print a
But this gives me the result with removing the first appearance 'no'like:
['no', 'no', 'yes', 'no', 'yes', 'no']
How can I achieve the desired result by removing all occurrences 'no'that are preceded by everything 'yes'on my list?