codewars 刷题第三道——shotrest word.py!
题目
"""
Simple, given a string of words, return the length of the shortest word(s).
String will never be empty and you do not need to account for different data types.
很简单,给定一串单词,返回最短单词的长度。
字符串永远不会为空,您不需要考虑不同的数据类型。
"""
解决代码
ef find_short(s):
# your code here
str_list = s.split(" ") # 按照空格将字符串分割并存为列表
len_list = []
for i in str_list:
len_list.append(len(i)) # 遍历得到每个字符串并将其长度存入列表中
l = min(len_list) # 取出最短的那个长度
return l # l: shortest word length
# def find_short(s):
# # your code here
# str_list = s.split(" ")
# # print(str_list)
# len_list = []
# for i in str_list:
# # print(len(i))
# str_len = len(i)
# len_list.append(str_len)
# # print(len_list)
# print(min(len_list))
# l = min(len_list)
# return l # l: shortest word length
# test.describe("Basic Tests")
find_short("bitcoin take over the world maybe who knows perhaps")
find_short("turns out random test cases are easier than writing out basic ones")
find_short("lets talk about javascript the best language")
find_short("i want to travel the world writing code one day")
find_short("Lets all go on holiday somewhere very cold")