Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
HOME - " Backward Each Word" solution in Uncategorized category for Backward Each Word by jsg-inet
def backward_string_by_word(text: str) -> str:
# your code here
def inverse_word(word:str) -> str:
inv_word=''
for x in word: inv_word= x + inv_word
return inv_word
def inverse_word_txt(tail_txt: str) -> str:
tail_txt_list=tail_txt.split()
num_words=len(tail_txt_list)
if num_words==0:
print('salida 1')
return text
elif num_words==1:
first_word=tail_txt_list[0]
inverse_first_word=inverse_word(first_word)
print('salida 2')
return tail_txt.replace(first_word, inverse_first_word)
else:
print(tail_txt_list)
first_word=tail_txt_list[0]
len_first_word=len(first_word)
inverse_first_word=inverse_word(first_word)
print(len_first_word)
print(tail_txt_list[1])
print(tail_txt[len_first_word:])
print(tail_txt[len_first_word:].index(tail_txt_list[1]))
cut_point=len_first_word+tail_txt[len_first_word:].index(tail_txt_list[1])
print(cut_point)
head_txt=tail_txt[:cut_point]
new_tail_txt=tail_txt[cut_point:]
new_head_txt=head_txt.replace(first_word, inverse_first_word)
print('salida 3')
print(new_head_txt)
print(new_tail_txt)
return new_head_txt+inverse_word_txt(new_tail_txt)
print ( 'fin')
print()
return inverse_word_txt(text)
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!")
June 11, 2021
Comments: