프로그래밍 문제/[Python] CheckIO
[CheckIO] Right to Left
UltraLowTemp-Physics
2020. 12. 9. 14:22
Problems: py.checkio.org/en/mission/right-to-left/
My solution:
import re
def left_join(phrases: tuple) -> str:
"""
Join strings and replace "right" to "left"
"""
dummy = ""
for string in phrases:
dummy = dummy + re.sub('right', 'left', string) + ","
return dummy[:-1]
if __name__ == '__main__':
print('Example:')
print(left_join(("left", "right", "left", "stop")))
#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!")
A good solution that I see
def left_join(phrases):
"""
Join strings and replace "right" to "left"
"""
return (",".join(phrases)).replace("right","left")