该函数接受一个字符串输入,去除标点符号,计算每个单词中的字母数,并返回原始字符串中最短单词的字母数。但是,它将答案作为列表返回。我需要它以整数形式返回结果。在这个给定的示例中它返回 [2],我需要它返回 2。我应该如何修改此代码?
def find_short(s):
import string
string_no_punct = s.strip(string.punctuation)
word_lenght_list = list(map(len, string_no_punct.split()))
word_lenght_list.sort()
new_list = word_lenght_list[:1]
return new_list
print(find_short("Tomorrow will be another day!"))
喵喵时光机
慕娘9325324
POPMUISE
哔哔one
随时随地看视频慕课网APP
相关分类