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

How to check each item in a list to see if it begins with the letter 'a'.

I know I need to do some kind of loop. I have tried looking in the help menu of python all about indexes, however I cant get my code to work properly. I feel like I might be over thinking it a little.

Am I wrong in assuming this: list = ['123', '456', '789'] 123 has an index of 0 456 has an index of 1 and 789 has an index of 2

If that is the case then I am not sure on how to check if a certain index of a list starts with something specific. In this case i need to check to see if it starts with an "a".

If you could either point me to a video that helps explain this, or give me a hint on which function I should be using, I would be most grateful.

def loopy(items):
    # Code goes here
    for item in loopy:
        if item.index(0) == "a":

1 Answer

Stuart Wright
Stuart Wright
41,103 Points

There are 3 things you need to fix in your code:

    for item in loopy:

loopy is the name of the function. items is the list variable you should be looping over.


This doesn't find the list item at index 0. It looks for the index for an element with value 0. To access the item at index 0 in your item you simply use item[0].


Again, loopy is the function name, which is not what you want to print out. You want to print the current item.

Hopefully this is enough to get you on the right track. Let me know if you need any more help.

Thank you so much! I was able to complete it with your help. It seems like a silly mistake, however I understand it better. Thanks again!