python 判断列表字符串元素首尾字符是否相同

 

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', '122771']))

 

posted @ 2018-11-16 10:29  anobscureretreat  阅读(1266)  评论(0编辑  收藏  举报