Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
re.sub + while solution in Clear category for Backspace Apply by kdim
from re import sub
def backspace_apply(val: str) -> str:
while '#' in val:
val = sub(r'^#+|[^#]#', r'', val)
return val
print("Example:")
print(backspace_apply("thna#m##e"))
assert backspace_apply("name") == "name"
assert backspace_apply("name#") == "nam"
assert backspace_apply("na##me") == "me"
assert backspace_apply("nam#e#") == "na"
assert backspace_apply("##name") == "name"
assert backspace_apply("name######") == ""
assert backspace_apply("nam######e") == "e"
assert backspace_apply("n###ame") == "ame"
assert backspace_apply("thna#m##e") == "the"
assert backspace_apply("oppo##r##t##u###nity") == "nity"
print("Not bad! Click 'Check' to earn cool rewards!")
Jan. 9, 2023
Comments: