Update longest_word_in_sentence.py

This commit is contained in:
Saurabh Mahapatra 2024-07-11 21:53:51 +05:30 committed by GitHub
parent b908d84c0f
commit 84628de8dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -13,12 +13,12 @@ def longest_word(sentence: str) -> str:
'thousand'
>>> longest_word("To be or not to be that is the question")
'question'
>>> longest_word("All that glitters is not gold")
'glitters'
>>> longest_word("Beauty is in the eye of the beholder")
'beholder'
>>> longest_word("A picture is worth a thousand words")
'thousand'
>>> longest_word("All that glitters is not gold")
'glitters'
"""
words = sentence.split()
return max(words, key=len) if words else ""