Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
re.search solution in Clear category for Word boundaries by kurosawa4434
from re import search
def boundaries(n: int, words: str) -> str:
if words[n:] and words[n] != ' ':
head = search('\S*$', words[:n]).group(0)
body = search('\S*', words[n:]).group(0)
return head + body
print("Example:")
print(boundaries(2, "a b c"))
# These "asserts" are used for self-checking
assert boundaries(2, "a b c") == "b"
assert boundaries(8, "+ - * / ( ) = 0") == "("
assert boundaries(12, "How do you do?") == "do?"
assert boundaries(6, "This is a very strange test...") == "is"
assert boundaries(0, "!!! What !!!") == "!!!"
assert boundaries(14, "test test ERROR") == "ERROR"
assert boundaries(1, "o o o!!!") == "error"
print("You are doing great! Now, it's time to check!")
Feb. 27, 2024
Comments: