Write a Python program to count the number of strings from a given list of strings.
Write a Python program to count the number of strings from a given list of strings. The string length is 2 or more and the first and last characters are the same.
Sample List : [‘abc’, ’11’, ‘xyz’, ‘aba’, ‘1221’, ‘2112’]
Expected Result : 2
def func(lst):
count = 0
for items in lst:
if len(items) > 2:
if items[0] == items[-1]:
count += 1
return count
print(func(['abc', '11', 'xyz', 'aba', '1221', '2112']))
About Author
I am a Web Developer, Love to write code and explain in brief. I Worked on several projects and completed in no time.
View all posts by Sunil Shaw