KnowledgeBoat Logo

Computer Science

Write a function, lenWords(STRING), that takes a string as an argument and returns a tuple containing length of each word of a string. For example, if the string is "Come let us have some fun", the tuple will have (4, 3, 2, 4, 4, 3).

Python String Manipulation

5 Likes

Answer

def lenWords(STRING):
    T = ()
    L = STRING.split()
    for word in L:
        length = len(word)
        T = T + (length, )
    return T

Answered By

4 Likes


Related Questions