CBSE Class 11 Computer Science
Question 99 of 104
List Manipulation — Question 13
Back to all questions 13
Question Question 11a
Write programs as per following specifications:
'''Print the length of the longest
string in the list of strings str_list.
Precondition : the list will contain
at least one element.'''
Solution
l = eval(input("Enter list of strings: "))
largeIdx = 0
largeLen = 0
for i in range(len(l)):
length = len(l[i])
if length > largeLen:
largeLen = length
largeIdx = i
print("Longest String:", l[largeIdx])Output
Enter list of strings: ["apple", "orange", "pear", "strawberry", "kiwi"]
Longest String: strawberry