Quiz>
"For centuries, left-handers have suffered unfair discrimination in a world designed for right-handers."
Santrock, John W. (2008). Motor, Sensory, and Perceptual Development.
"Most humans (say 70 percent to 95 percent) are right-handed,
a minority (say 5 percent to 30 percent) are left-anded,
and an indeterminate number of people are probably best described as ambidextrous."
Scientific American. www.scientificamerican.com
One of the robots is charged with a simple task: to join a sequence of strings into one sentence to produce
instructions on how to get around the ship. But this robot is left-handed and has a tendency to joke around and confuse its right-handed friends.
You are given a sequence of strings.
You should join these strings into a chunk of text where the initial strings are separated by commas.
As a joke on the right handed robots, you should replace all cases of the words "right" with the word "left",
even if it's a part of another word. All strings are given in lowercase.
Input:
A sequence of strings.
Output:
The text as a comma-separated string.
Example:
left_join(("left", "right", "left", "stop")) == "left,left,left,stop"
left_join(("bright aright", "ok")) == "bleft aleft,ok"
left_join(("brightness wright",)) == "bleftness wleft"
left_join(("enough", "jokes")) == "enough,jokes"
How it is used:
This is a simple example of operations using strings and sequences.
Precondition:
0 < len(phrases) < 42
def left_join(phrases: tuple) -> str:
"""
Join strings and replace "right" to "left"
"""
return "left"
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!")
Solve>
1. , 를 구분자로 모두 join 하여 문자를 변경한다.
replace()는 문자열 변경 메소드이다.
def left_join(phrases):
return (','.join(phrases)).replace('right', 'left')
Code>
def left_join(phrases):
return (','.join(phrases)).replace('right', 'left')
Example>
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!")
Result>
Example:
left,left,left,stop
Coding complete? Click 'Check' to review your tests and earn cool rewards!
'Python_Matter > [Check_IO]Home' 카테고리의 다른 글
Second Index (0) | 2020.04.14 |
---|---|
Days Between (0) | 2020.04.14 |
Even the Last (0) | 2020.04.12 |
Sum Numbers (0) | 2020.04.12 |
Split List (0) | 2020.04.12 |