Skip to content

Commit 1b9bde3

Browse files
authored
Update longest_word_in_sentence.py
1 parent 8336e54 commit 1b9bde3

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

strings/longest_word_in_sentence.py

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
def longest_word(sentence: str) -> str:
22
"""
33
Finds the longest word in a sentence.
4-
54
>>> longest_word("The quick brown fox jumped over the lazy dog")
65
'jumped'
76
>>> longest_word("Python is amazing")
@@ -10,24 +9,20 @@ def longest_word(sentence: str) -> str:
109
''
1110
>>> longest_word("a")
1211
'a'
13-
>>> longest_word("A tie between words")
14-
'between'
15-
>>> longest_word("All words are same length")
16-
'All'
17-
>>> longest_word("Multiple words with the same longest length")
18-
'Multiple'
19-
>>> longest_word("Trailing spaces at the end ")
20-
'Trailing'
21-
>>> longest_word(" Leading spaces at the start")
22-
'Leading'
23-
>>> longest_word("Special characters !@#$%^&*() should be ignored")
24-
'characters'
12+
>>> longest_word("A journey of a thousand miles begins with a single step")
13+
'thousand'
14+
>>> longest_word("To be or not to be that is the question")
15+
'question'
16+
>>> longest_word("All that glitters is not gold")
17+
'glitters'
18+
>>> longest_word("Beauty is in the eye of the beholder")
19+
'beholder'
20+
>>> longest_word("A picture is worth a thousand words")
21+
'thousand'
2522
"""
2623
words = sentence.split()
27-
return max(words, key=len) if words else ""
28-
24+
return max(words, key=len) if words else ''
2925

3026
if __name__ == "__main__":
3127
from doctest import testmod
32-
3328
testmod()

0 commit comments

Comments
 (0)