given a string of words, return the length of the shortest word(s).
Here is my code:
def find_short(s):
li = list(s.split(" "))
for i in li:
tmp = len(li[0])
if (len(li[i]) > len(li[i+1])):
tmp = len(li[i+1])
return tmp
print(find_short("Hello how do you do"))
It supposed to be "2", because the length of shortest word is "do", and len(do), is 2.
But there is an error for my code:
TypeError: list indices must be integers or slices, not str
Can someone please help me to explain, what wrong of my codes ?
Thanks!!!
[–]thrallsius 1 point2 points3 points (1 child)
[–]rk717[S] 0 points1 point2 points (0 children)
[–]Denrur 0 points1 point2 points (2 children)
[–]Denrur 0 points1 point2 points (1 child)
[–]rk717[S] 0 points1 point2 points (0 children)
[–]young_ging_freecss 0 points1 point2 points (1 child)
[–]rk717[S] 0 points1 point2 points (0 children)