开发者

Newbie Python programmer tangling with Lists

Here's what I've got so far:

# 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 sam开发者_开发百科e.
# Note: python does not have a ++ operator, but += works.
def match_ends(words):
  counter = 0
  for word in words:
    if len(word) >= 2 and word[0] == word[-1]:
      counter += counter
  return counter
  # +++your code here+++
  return

I'm following the Google Python Class, so this isn't homework, but me just learning and improving myself; so please no negative comments about 'not doing my homework'. :P

What do you guys think I'm doing wrong here?

Here's the result:

match_ends
  X  got: 0 expected: 3
  X  got: 0 expected: 2
  X  got: 0 expected: 1

I'm really loving Python, so I just know that I'll get better at it. :)


You should do:

counter += 1

instead of

counter += counter

which stays at 0 for all ages.


counter += 1

you add 0 to 0

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜