Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
while, index solution in Clear category for Backspace Apply by Sim0000
def backspace_apply(val: str) -> str:
while '#' in val:
n = val.index('#')
if n > 0:
val = val[:n-1] + val[n+1:]
else:
val = val[1:]
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. 31, 2022
Comments: