Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Step by step solution in Clear category for Backward Each Word by ajevip
def backward_string_by_word(text: str) -> str:
# Reversing a string:
textrev = text[::-1]
# Creating a list with the words of the string:
txtlist = textrev.split(" ")
# Reversing the order of the list:
txtlist.reverse()
# Joining the elements of the list into a string:
txt = " ".join(txtlist)
return txt
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!")
Dec. 17, 2020
Comments: