mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-05-15 13:47:22 +00:00
Update longest_word_in_sentence.py
This commit is contained in:
parent
b31d2b2912
commit
8336e54e91
@ -10,6 +10,18 @@ def longest_word(sentence: str) -> str:
|
|||||||
''
|
''
|
||||||
>>> longest_word("a")
|
>>> longest_word("a")
|
||||||
'a'
|
'a'
|
||||||
|
>>> longest_word("A tie between words")
|
||||||
|
'between'
|
||||||
|
>>> longest_word("All words are same length")
|
||||||
|
'All'
|
||||||
|
>>> longest_word("Multiple words with the same longest length")
|
||||||
|
'Multiple'
|
||||||
|
>>> longest_word("Trailing spaces at the end ")
|
||||||
|
'Trailing'
|
||||||
|
>>> longest_word(" Leading spaces at the start")
|
||||||
|
'Leading'
|
||||||
|
>>> longest_word("Special characters !@#$%^&*() should be ignored")
|
||||||
|
'characters'
|
||||||
"""
|
"""
|
||||||
words = sentence.split()
|
words = sentence.split()
|
||||||
return max(words, key=len) if words else ""
|
return max(words, key=len) if words else ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user