我是靠谱客的博主 懦弱春天,最近开发中收集的这篇文章主要介绍checkio练习题:right-to-left,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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 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 as a tuple of strings (unicode).

Output: The text as a 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):
    """
        Join strings and replace "right" to "left"
    """
    # 先以逗号拼接字符,然后进行字符串替换
    return ','.join(phrases).replace('right', 'left')

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", "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!")

 

最后

以上就是懦弱春天为你收集整理的checkio练习题:right-to-left的全部内容,希望文章能够帮你解决checkio练习题:right-to-left所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部