Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Shopping List App Continue

Using the index of a string

How to set the Index 0 in '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 the current member.'

breaks.py
def loopy(items):
    for item in items:
        if item.index[0] =="a":
            continue
        else:
            print(item)

2 Answers

Steven Parker
Steven Parker
231,248 Points

You almost have it. But .index is a method used for finding an index for certain contents, you won't need that here.

:point_right: You just need to get the first letter of the item (index of 0), using the indexing operator: [] (brackets).

        if item[0] == "a":
Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

You need to change your for statement so it loops until it gets to last item. You need a function that determines how many items are in array then make it part of for statement.

Steven Parker
Steven Parker
231,248 Points

Actually, he for...in statement he has already handles that nicely, without needing to keep track of the count of items.