Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
MySolutionBetweenMarkers solution in Clear category for Between Markers by jemg2030
def between_markers(text: str, begin: str, end: str) -> str:
"""
returns substring between two given markers
"""
# your code here
start_index = text.find(begin)
if start_index == -1:
start_index = 0
else:
start_index += len(begin)
end_index = text.find(end)
if end_index == -1:
end_index = len(text)
if end_index < start_index:
return ''
return text[start_index:end_index]
print("Example:")
print(between_markers("What is >apple<", ">", "<"))
assert between_markers("What is >apple<", ">", "<") == "apple"
assert (
between_markers("My new site", "", "")
== "My new site"
)
assert between_markers("No[/b] hi", "[b]", "[/b]") == "No"
assert between_markers("No [b]hi", "[b]", "[/b]") == "hi"
assert between_markers("No hi", "[b]", "[/b]") == "No hi"
assert between_markers("No ", ">", "<") == ""
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 7, 2023