我正在练习测试,编写了这些代码,但是似乎不把^ {CD1>}标记成句子的种子,但只要使用就行。
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]]
目标是返回这些句子中的最大字数。
所以
print sol2("This is one. And this is two. Are you serious? Hi!")
应该输出4
您的代码无法工作,因为它在第一次循环迭代后返回
return
关键字。它永远不会为"!"
运行你有没有考虑过使用正则表达式
相关问题 更多 >
编程相关推荐