Skip to content

Commit 8336e54

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

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎strings/longest_word_in_sentence.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ def longest_word(sentence: str) -> str:
1010
''
1111
>>> longest_word("a")
1212
'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'
1325
"""
1426
words = sentence.split()
1527
return max(words, key=len) if words else ""

0 commit comments

Comments
 (0)