私はこれらのコードをテストして書いていますが、!
という文章をsperatorとみなしていません。感嘆符をちょうど完全な停止の横の別の文章区切り記号としてconjderすることはできますか?
for sep in (".", "!", "?")
sentences = S.split(sep)
num_of_sentences = len(sentences)
# print num_of_sentences
tempDict = {}
for i, sent in enumerate(sentences):
tempDict[i] = len(sent.split())
print sentences
return tempDict[max(tempDict.iteritems(), key=operator.itemgetter(1))[0]]
目的は、これらの文のうち、単語の最大数を返すことです。それはreturn
キーワードに、最初のループ反復の後に返すため はそう print sol2("This is one. And this is two. Are you serious? Hi!")
出力4
これはすべて関数内にありますか?もしそうなら、 'return'キーワードは最初の計算されたループの結果を返すだけで、各ループの結果ではありません(2つの他のループは実行されません)。関数のコード全体が必要なのかもしれないと思う。 – notcompletelyrational
これは宿題ですか(https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions)ですか? – wwii