这里是一个使用Python编写的函数示例:
def shortest_word(words):
shortest = None
shortest_length = float('inf')
for word in words:
if len(word) < shortest_length:
shortest = word
shortest_length = len(word)
return shortest
你可以像这样调用该函数:
word_list = ["apple", "banana", "cat", "dog"]
print(shortest_word(word_list))
输出将会是:
cat
这是因为在给定的列表中,"cat"是长度最短的单词。