我在python 2上通过谷歌参加了一个在线初学者课程,但我无法找到其中一个问题的答案。给你,提前感谢你的帮助!
# A. match_ends
# Given a list of strings, return the count of the number of
# strings where the string length is 2 or more and the first
# and last chars of the string are the same.
# Note: python does not have a ++ operator, but += works.
def match_ends(words):
a = []
for b in words:
retun
我尝试了一些不同的东西。这正是我最后一次尝试的地方,我决定寻求帮助。我花了更多的时间思考这个问题,而不是提及
你应该仔细阅读课程材料。如果你对Python有初级的理解,这个问题可以很容易地解决。请参阅以下代码片段:
def match_ends(words):
count = 0
for word in words:
if len(word) >= 2 and word[0] == word[-1]:
count += 1
return count