How to find the longest word in a string with Python

1 Answer

0 votes
def longest_word(s):
    words = s.split()
    
    return max(words, key=len)

print(longest_word("Could you recommend a good restaurant nearby?"))



'''
run:

restaurant

'''

 



answered Mar 2 by avibootz
...