Have the function LongestWord(sen) take the sen parameter being passed and return the largest word in the string. If there are two or more words that are the same length, return the first word from the string with that length. Ignore punctuation and assume sen will not be empty.
Sample Test Cases
Input:"fun&!! time"
Output:"time"
Input:"I love dogs"
Output:"love"
import re
class Solution:
def longest_word(self, sen):
# code goes here
resen = re.sub('[^a-zA-Z ]+', '', sen)
list1 = resen.split()
return max(list1, key=len)
# keep this function call here
obj = Solution()
print(obj.longest_word(input()))
q q qw qw qwe qwe qqwrq qwwer
OUTPUT
qqwrq
Comments
Post a Comment