w3resource logo


Python Exercises

Python: Function that takes a list of words and returns the length of the longest one


Write a Python function that takes a list of words and returns the length of the longest one.

Sample Solution :

Python Code :

def find_longest_word(words_list):
    word_len = []
    for n in words_list:
        word_len.append((len(n), n))
    word_len.sort()
    return word_len[-1][1]

print(find_longest_word(["PHP", "Exercises", "Backend"]))

Console :

Copy and paste the above code and press "Enter key" to execute :

Post your code through Disqus