Computer Science, asked by priyanshudhiman807, 5 hours ago

WAP in Python to create a list of Strings and print the length of

individual elements(strings) of the list.

e.g.:

List1=[“Raghav”,”Aishwarya”,”Stuti”]

The output should be:

Raghav : 6

Aishwarya : 9

Stuti : 5​

Answers

Answered by ItzAditt007
6

Answer:-

The Program Is As Follows:-

If you want that user will enter the list then the program will be:-

__________________________________

a = 0

list1 = eval(input("Enter The list of strings: "))

for i in range (lena(list1)):

print(list1[a], " : ", len(list1[a]))

a += 1

__________________________________

Explanation of Above program:-

  • In first line the value of a is defined as 0.

  • Second line will take a list as a input from user.

  • Third line is a for loop which will print the length of the all elements of the list in the desired form.

__________________________________

If The List Is Already Given By You Then The Program Will Be:-

list1 = ["First Element", "Second Element", " Third Element"]

print(list1[0], " : ", len(list1[0]))

print(list1[1], " : ", len(list1[1]))

print(list[2], " : ", len(list1[2]))

__________________________________

Similar questions