Codewars notes -Seence Smash

Solution

def smash(words):
    sentence = ""
    
    for i in words:
        sentence = sentence + ' ' + i 
        #在每个单词前加一个空格
        
    return sentence.strip(' ')
        #strip('a') 去掉字符串首尾的 字符
        #参数'a' 是目标要去掉的字符
smash(["hello", "world"])
smash(["hello", "amazing", "world"])
smash(["this", "is", "a", "really", "long", "sentence"])

 

posted @ 2022-06-24 19:40  大序列  阅读(19)  评论(0编辑  收藏  举报