From 8336e54e9194c9d8544d543edcc359fddbad1db8 Mon Sep 17 00:00:00 2001 From: Saurabh Mahapatra <98408932+its-100rabh@users.noreply.github.com> Date: Sun, 7 Jul 2024 10:02:14 +0530 Subject: [PATCH] Update longest_word_in_sentence.py --- strings/longest_word_in_sentence.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/strings/longest_word_in_sentence.py b/strings/longest_word_in_sentence.py index ed1da448f..0259e0ad5 100644 --- a/strings/longest_word_in_sentence.py +++ b/strings/longest_word_in_sentence.py @@ -10,6 +10,18 @@ def longest_word(sentence: str) -> str: '' >>> longest_word("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() return max(words, key=len) if words else ""