python修炼——codewars_3!

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")
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值