Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Long :o solution in Creative category for Right to Left by xFrodas
def left_join(phrases: tuple, searched_word="right", change_to="left") -> str:
index = len(phrases)
length_of_searched_word = len(searched_word)
string = ""
list_of_pieces = []
for i in range(index):
piece = phrases[i]
index_piece = len(piece)
cache = ""
if not piece == change_to:
alt_a = 0
times_to_multiply = 1
for a in range(index_piece):
piece_of_piece = piece[alt_a:alt_a + 1]
if piece[alt_a:alt_a + length_of_searched_word] == searched_word:
cache = cache + change_to
alt_a = (length_of_searched_word * times_to_multiply) + a
times_to_multiply = times_to_multiply + 1
continue
elif alt_a == index_piece:
cache = cache + piece_of_piece
break
else:
cache = cache + piece_of_piece
alt_a = alt_a + 1
list_of_pieces.append(cache)
else:
list_of_pieces.append(piece)
for i in range(len(list_of_pieces)):
if string == "":
string = string + list_of_pieces[i]
else:
string = string + "," + list_of_pieces[i]
if list_of_pieces == []:
string = "There is nothing!"
"""
Join strings and replace "right" to "left"
"""
return string
if __name__ == '__main__':
print('Example:')
print(left_join(()))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert left_join(("left", "right", "left", "stop")) == "left,left,left,stop", "All to left"
assert left_join(("bright aright", "ok")) == "bleft aleft,ok", "Bright Left"
assert left_join(("brightness wright",)) == "bleftness wleft", "One phrase"
assert left_join(("enough", "jokes")) == "enough,jokes", "Nothing to replace"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
June 20, 2021