filmov
tv
count number of string | Python List | python shorrts | python for beginner #shorts #youtubeshorts

Показать описание
Write a Python program to count the number of strings
where the string length is 2 or more and the first and
last character are same from a given list of strings.
Sample List:['abc', 'xyz', 'aba', '1221',''343','def']
Expected Result : 3
code:
words = ['abc','xyz','aba','1221','343','def']
count = 0
for word in words:
if len(word)1 and word[0]==word[-1]:
count += 1
print(count)
output:
3
where the string length is 2 or more and the first and
last character are same from a given list of strings.
Sample List:['abc', 'xyz', 'aba', '1221',''343','def']
Expected Result : 3
code:
words = ['abc','xyz','aba','1221','343','def']
count = 0
for word in words:
if len(word)1 and word[0]==word[-1]:
count += 1
print(count)
output:
3