需要查找字符串中最长的单词并打印该单词。 1.)要求用户输入以空格分隔的句子。 2.)查找并打印最长的单词。如果两个或两个以上的单词的长度相同,则会打印第一个单词。比较字符串中单词的长度
这是我迄今为止
def maxword(splitlist): #sorry, still trying to understand loops
for word in splitlist:
length = len(word)
if ??????
wordlist = input("Enter a sentence: ")
splitlist = wordlist.split()
maxword(splitlist)
试图字的lenghts比较在森泰斯当我击中墙壁。我是一名使用python 5周的学生。
谢谢你的回答。这正是我陷入困境的地方。我知道我想做什么,我只是不知道如何实现它。寻求帮助是我的最后手段。 – Mixtli 2014-11-23 20:53:27