Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Loooong solution solution in Creative category for Right to Left by _Chico_
def find_pos(text:str) -> list:
length = len(text)
my_list = []
for pos in range(length):
if pos < length-4 and text[pos:pos+5] == 'right':
my_list.append(pos)
return my_list
def replace(str:str) -> str:
storage = ''
_list = find_pos(str)
first_pos = 0
for index in _list:
text = str[first_pos: index]
storage = storage + text + 'left'
first_pos = index + 5
if (first_pos < len(str)):
storage = storage + str[first_pos: len(str)]
return storage
def left_join(phrases:tuple) -> str:
"""
Join strings and replace "right" to "left".
"""
a = ''
pos = 0
while (pos < len(phrases)):
x = replace(phrases[pos])
if pos == len(phrases) - 1:
a = a + x
else:
a = a + x + ","
pos += 1
return a
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert left_join(("left", "right", "left", "stop")) == "left,left,left,stop"
assert left_join(("bright aright", "ok")) == "bleft aleft,ok"
assert left_join(("brightness wright",)) == "bleftness wleft"
assert left_join(("enough", "jokes")) == "enough,jokes"
April 27, 2021
Comments: