Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Between Markers by Pavellver
def between_markers(text: str, begin: str, end: str) -> str:
if begin not in text and end in text:
return text[:text.rfind(end[0])]
if begin in text and end not in text:
return text[text.index(begin[-1]) + 1:]
if begin not in text and end not in text:
return text
return text[text.index(begin[-1]) + 1: text.rfind(end[0])].replace(begin, '').replace(end, '')
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!")
Feb. 3, 2023
Comments: