Sunday, January 29, 2017

Longest Word in a List

Tags

Question::

Write a function find_longest_word() that takes a list of words and returns the length of the longest one

Code::
def longest(l):
    long=0
    word=""
    for j in l:
        if(long<len(j)):
            long=len(j)
            word=j
    return [word,long]

n=input("Enter words:")
nt=n.split(",")
long=longest(nt)

print("Longest Word with length:",long)

Output::