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

skipping items if it is start with "a"!!

this is the question (Loop through each item in items again. If the character at index 0 of the current item is the letter "a", continue to the next one. Otherwise, print out the current member. Example: ["abc", "xyz"] will just print "xyz".) I tried this codes but it did not work can you help me figure out what is wrong with it?? Sincerely,,

breaks.py
def loopy(items):
    # Code goes here
    for thing in items:
        if (thing).index[0]=='a':
            continue
        else:
            print (thing)

2 Answers

Hi there,

You're pretty close with that. There's no need to use the word index, though. You can access the first element of the current iteration by just using square brackets, like thing[0]. And you don't need to surround thing in parentheses, except for the print part. The rest is correct.

Steve.

Michael Hulet
Michael Hulet
47,913 Points

In Python, when we say "index", we mean a number that represents a specific place in a list. lists on their own have no property or method named index, and to get an object from a specific index in a list, you just use the subscript with the proper list name directly, like this:

some_list = ["This", "is", "a", "list"]
string = some_list[0] # string is now equal to "This"

To be clear, all the information above also applies to strs, so if you're trying to get a character at a specific index of a string, the same syntax will work