Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Shopping List App Continue

Cant get past code challenge

I can figure out what I am doing wrong. Can someone explain why this is not working?

Same idea as the last one. My loopy function needs to skip an item this time, though. Loop through every item in items. If the current item's index 0 is the letter "a", continue to the next one. Otherwise, print out every member of items.

def loopy(items):

for item in items:
  if item.index('a') == 0:
    continue
  else:
    print(item)

1 Answer

Seth Reece
Seth Reece
32,867 Points

Hi Aaron,

You are close, to check the first letter in a string, the index is 0. Indexes are stated using square brackets. You want to use:

if item[0] == 'a':
    continue

Ugh, THANKS!

Seth I have a question. I know this is an old post, but I was having an issue with this too and your code helped me get past it. I'm confused as to why you're referencing item as index 0 when the list is considered "items"? It would make sense to me from VBA atleast that in order to test item in index 0 you'd test the list for [0] rather than testing the item itself with a position.

Seth Reece
Seth Reece
32,867 Points

Hi Tyler,

Strings also have indexes in Python. This challenge is asking to loop through a list of strings and check the first letter (index 0) in each string and compare to "a".