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

Shopping List 2 - going wrong.

So I've read and tried to understand this coding challenge but I'm not sure where I'm going wrong. I've looked up the .index and thought I placed it in the right place. Clearly not.

Can any one point me in the right direction.

breaks.py
def loopy(items):
    for item in items:
        if item.index == "a"
            continue
        else:
            print(item)
Tony Martin
Tony Martin
5,570 Points

I think that .index is a method, meaning you need to call it instead of setting it equal to something if you want to use it, however, I'm not sure that's what you want to use here. .index returns the index where the first instance of the value passed into it was found. Here, we don't really need the index of any value in the list. Instead the instructions ask:

  1. If the character at index 0 of the current item is the letter "a"... +That's pretty specific. if whatever is at the 0 index of the current item in the items list --better known as, in this case, item[0]-- if whatever is there is an 'a'...
  2. continue to the next one.
    • if that stuff above is true (whatever's at item[0] == 'a') then skip that entire item homie.
  3. Otherwise, print out the current member.
    • if it's not true, print this entire item

the for loop will then move on to the next item in the items list, and then should check the first character in the first item for 'a' again just like before. wash, rinse, repeat.

So, you'd want to write (if I'm remembering this all correctly):

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

instead of item.index. I think...

edit: also note that you're missing a colon at the end of your if statement.

1 Answer

Hello

you are missing : as in

if item.index == "a":

and I suspect you mean to code it as below:

def loopy(items): for item in items: if item == "a": continue else: print(item)

loopy("ababab")

if this answers you question, please make the question as answered.

Thank