Length of Last word (GFG)

 Given a string S consisting of upper/lower-case alphabets and empty space characters ‘ ‘. The string may contain spaces at the end. You will have return the length of last word which consists of alphabets only.

Input:
First line of input consists of T test cases. The only line of every test case consists of String S.

Output:
You have to return the length of last word of the string.

Constraints:
1<=T<=100
1<=|String length|<=100

Example:
Input:

2
Geeks for Geeks
Start Coding Here
Output:
5
4


SOLUTION:

t=int(input())

for i in range (t):

    s=list(map(str,input().split()))

    n=len(s)

    if n==1:

        print(len(s[0]))

    else:

        print(len(s[-1]))

Comments

Popular posts from this blog

Short Notes Of computer Network

Short Note of Data Structure

Sort in specific order (GFG)