Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Different than just reversing the string! solution in Uncategorized category for Backward Each Word by BootzenKatzen
#I thought this was the same as the other "reverse the word" one but it is NOT
# Because you're reversing the words, but not the order of the words
# So you have to reverse each word individually then join them back together in order
def backward_string_by_word(text: str) -> str:
return ' '.join(x[::-1] for x in text.split(' '))
print("Example:")
print(backward_string_by_word("butts"))
# These "asserts" are used for self-checking
assert backward_string_by_word("") == ""
assert backward_string_by_word("world") == "dlrow"
assert backward_string_by_word("hello world") == "olleh dlrow"
assert backward_string_by_word("hello world") == "olleh dlrow"
assert backward_string_by_word("welcome to a game") == "emoclew ot a emag"
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 30, 2023
Comments: