Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
last check is owful solution in Clear category for Backward Each Word by Nikolaj_Strom
def backward_string_by_word(text: str) -> str:
text2 = text.replace(' ', ' * ')
words = text2.split()
#
for i in range(len(words)):
if words[i].isalpha():
words[i] = words[i][::-1]
words = ''.join(words).replace('*', ' ')
return words
if __name__ == '__main__':
print("Example:")
print(backward_string_by_word(''))
# These "asserts" are used for self-checking and not for an auto-testing
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("Coding complete? Click 'Check' to earn cool rewards!")
Jan. 26, 2021
Comments: