Suppose I have a list of strings:
first item
second item
# first commented item
third item
# second commented item
How do I remove the first item that starts with #
from the list?
Expected result:
first item
second item
third item
# second commented item
>>> items = ["First", "Second", "# First", "Third", "# Second"]
>>> for e in items:
... if e.startswith('#'):
... items.remove(e)
... break
...
>>> items
['First', 'Second', 'Third', '# Second']
items = ["First", "Second", "# First", "Third", "# Second"]
for i in xrange(len(items)):
if items[i][0] == '#':
items.pop(i)
break
print items
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With