First solution in Clear category for Between Markers (simplified) by sensorama2000
def between_markers(text: str, begin: str, end: str) -> str:
returns substring between two given markers
# your code here
start_marker = text.find(begin) + len(begin) if text.find(begin) >= 0 else 0
end_marker = text.find(end) if text.find(end) >= 0 else None
return text[start_marker:end_marker] if not (start_marker == 0 and end_marker is None) else text
if __name__ == '__main__':
print(between_markers('What is >apple<', '>', '<'))
# These "asserts" are used for self-checking and not for testing
assert between_markers('What is >apple<', '>', '<') == "apple"
assert between_markers('What is [apple]', '[', ']') == "apple"
assert between_markers('What is ><', '>', '<') == ""
assert between_markers('>apple<', '>', '<') == "apple"
print('Wow, you are doing pretty good. Time to check it!')
Feb. 20, 2021