我试着在一个句子上使用一个先前定义的函数,我已经把它分成了单词串,但是我不知道如何循环它。请帮忙。代码如下。你知道吗
def pig_latin_sentence(sentence):
''' Converts a string of words separated by spaces to Pig Latin'''
words=sentence.split(" ")
for
pig_latin(word)
sentence2=sentence2+word
return sentence2
Tags:
如果pig\u拉丁函数适当地添加空格,则循环应该如下所示:
但如果不是这样,那么使用join并避免使用map函数的for循环可能会更好:
相关问题 更多 >
编程相关推荐