tags:

views:

70

answers:

2

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 same.
# 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. :)

+2  A: 

You should do:

counter += 1

instead of

counter += counter

which stays at 0 for all ages.

Alexander Gessler
Thanks, I didn't notice that obvious bug. Learning bro!
Serg
A: 
counter += 1

you add 0 to 0

bgbg