Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Between Markers (simplified) solution in Clear category for Between Markers (simplified) by bart.moura
def between_markers(text: str, begin: str, end: str) -> str:
"""
returns substring between two given markers
"""
# your code here
return text[text.index(begin)+1:text.index(end)]
''' OR
a = 0
b = 0
for x in range(0, len(text), 1):
if text[x] == begin:
a = x+1
for y in range(0, len(text), 1):
if text[y] == end:
b = y
return text[a:b]
'''
if __name__ == '__main__':
print('Example:')
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!')
Oct. 8, 2020