I’m trying to complete a challenge on Codewars that requires a code that returns the length of the shortest word in a string. My thought process is as follows:
- Count the number of letters in each word
- Return the length of the word that had the smallest number of letters
I was thinking of adding each word in the string to a list and then… I’m not sure? Can I use the len() function to count the length of each item in a list? How do I get Python to return the item with the smallest length?
Here is what I have so far:
Beneath line 6 I was thinking of writing
length_of_word = len(item) but there are multiple items in the list of each word! Wouldn’t this just count the length of each word, add them, and assign it to that variable? Any help would be appreciated.