DEV Community

Discussion on: Find longest word in a given string

Collapse
 
dannyaziz97 profile image
Danny Aziz • Edited

I know one of the tags is 'Javascript' but here is how I would do it in Python:

def get_longest_word(sentence):
    return max(sentence.split(' '), key=lambda x: len(x))

get_longest_word('Iam a verrrrry loooongggg sentence')
# result: loooongggg