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

  • برمجة
  • برمجة بايثون

 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.

الأجوبة

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']))
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...