我有一个单词列表:words = ["alpha","omega","up","down","over","under","purple","red","blue","green"]我有两个函数可以找到这个列表中最短和最长的单词:
def bigWords(list=[], *args):
largestWord=""
largestLen=0
for word in list:
if largestWord
largestWord=len(word)
largestWord=word
print "The longest word(s) in the list is %s." % largestWord
def smallWords(list=[], *args):
smallestWord=""
smallestLen=0
for word in list:
if smallestLen>len(word):
smallestLen>len(word)
smallestWord=word
print "The shortest word(s) in the list is: %s." % (smallestWord)
我嵌套了这些函数,所以我可以立即调用它们:
def callFunctions():
###Words###
words=["alpha","omega","up