Newbie Python programmer tangling with Lists.

Posted by Sergio Tapia on Stack Overflow See other posts from Stack Overflow or by Sergio Tapia
Published on 2010-03-21T19:40:58Z Indexed on 2010/03/21 19:41 UTC
Read the original article Hit count: 482

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about python

Related posts about newbie