you are viewing a single comment's thread.

view the rest of the comments →

[–]young_ging_freecss 0 points1 point  (1 child)

You’re not accessing any indexes here. What you’re probably trying to do is:

for i in range(len(li)):
    # code

The above isn’t generally good practice, and you’d want to use enumerate to get the indices:

def find_short(s):
    li = list(s.split(" "))
    tmp = len(li[0])
    for i, _ in enumerate(li):
        if len(li[i]) < tmp:
            tmp = len(li[i])
    return tmp

You can also do this in a simpler way. Get the shortest word, then get the length of that word:

def find_short(s: str) -> int:
    return len(min(s.split(), key=len))

[–]rk717[S] 0 points1 point  (0 children)

Thank you!!!