Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
string.find is better than string.index solution in Clear category for Second Index by ArchTauruS
"""string.find is better than string.index
string.index method will through out an exception, while string.find will return
-1 when the sub-string is not found in the text. So I use two find methods, the
first one will index for the first letter, and the second one will locate the
second letter. No matter how many that letter is in the text, this two finds
will always give the index of the second letter, or -1 if the is one or less.
"""
def second_index(text, symbol):
index = text.find(symbol, text.find(symbol)+1)
return index if index != -1 else None
Nov. 8, 2018
Comments: