Finding the shortest string in a string of words in python

后端 未结 4 952
后悔当初
后悔当初 2021-01-28 02:30

I want to write a function that would return the length of the shortest string in a string of words. Sample: \"I eat apples\" would return 1 since \"I\" is the shorted string. T

4条回答
  •  我在风中等你
    2021-01-28 03:15

    line = "I eat apples"
    mins = min(len(word) for word in line.split())
    print(mins)
    

    line.split() will split line into list of words and then just finding the minimum length

提交回复
热议问题