Let's say I am having a list as:
a = ['no', 'no', 'no', 'yes', 'no', 'yes', 'no']
Here I want to remove every 'no'
which is preceded by every 'yes'
. So my resultant list should be like:
['no', 'no', 'yes', 'yes', 'no']
I've found that in order to remove an element from a list by its value, we may use list.remove(..)
as:
a = ['no', 'no', 'no', 'yes', 'no', 'yes', 'no']
a.remove('no')
print a
But it gives me result with only removing first occurrence of 'no'
as:
['no', 'no', 'yes', 'no', 'yes', 'no']
How can I achieve the desired result by removing all the occurrence of 'no'
which are preceded by all 'yes'
in my list?