Python program: Write a program to count the number of strings and print them satisfying the given conditions

Python program: Write a program to count the number of strings and print them satisfying the given conditions

1. The string length is 2 or more
2. The first and last characters are the same
\
-----------------------------------------

list_items = ["hi","hello","pip","pop","city","high"]
count = 0

for string in list_items:
    if(len(string)>=2 and string[0] == string[-1]):
        print(string)
        count = count + 1
        
print(count)

-----------------------------------------

Output: 
pip
pop
high
3

Post a Comment

0 Comments