Suppose I have a list of strings:
first item second item # first commented item third item # second commented item
How to 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
Source: https://habr.com/ru/post/1339575/More articles:Onlayout method for custom layout extending RelativeLayout - androidHow to establish and read contacts on a parallel port with C ++? - c ++How does my C program check for execute permission for a given file? - cIterate through all trees of a given size - mathHow to save and redraw screen contents in OpenGL ES - objective-c- infinite loop problem viewDidLoad ... (iOS) - iosDrupal viewer - drupalWriting text to PDF via NSString - iosUITextView delegate class call when text is clicked? What's happening? - iphoneIs ipython a replacement or works side by side with regular python? - pythonAll Articles