Computer Science, asked by bhavanakodavali92, 8 months ago

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

Answers

Answered by pranjalggs
11

Answer:

def match_words(words):

 ctr = 0

 for word in words:

   if len(word) > 1 and word[0] == word[-1]:

     ctr += 1

 return ctr

print(match_words(['abc', 'xyz', 'aba', '1221']))

Explanation:

Answered by shkulsum3
0

Here is a python program to count the number of strings where the string length is 2 or more and the first and last character are the same from a given list of strings:

def count_strings(strings):

   count = 0

   for string in strings:

       if len(string) >= 2 and string[0] == string[-1]:

           count += 1

   return count

strings = ['abc', 'xyz', 'aba', '1221']

result = count_strings(strings)

print("The number of strings where the string length is 2 or more and the first and last character are the same:", result)

The output of the program will be:

The number of strings where the string length is 2 or more and the first and last character are the same: 2

To know more about  Python visit : https://brainly.in/question/7697308

https://brainly.in/question/11818321

#SPJ3

Similar questions