Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First: nested use of find solution in Clear category for Second Index by leggewie
def second_index(text: str, symbol: str) -> [int, None]:
"""
returns the second index of a symbol in a given text
"""
pos = text.find(symbol, text.find(symbol) + 1)
if pos == -1:
return None
else:
return pos
# I'm happy with line 5 to find the position. I'm not so happy with lines 6 to 9,
# there must be a better way to replace a return value of -1 with None.
#
# Suggestions welcome!
May 26, 2021