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

Need help with this please

Hi, I wrestled with this for a while but it only seems to work a bit. Meaning, the following code does skips the 0th element and prints xyz if the array is items = ["abc","xyz" ] but if the list has more elements it skips all elements and prints the last one. def loopy(items): for item in items: if items[0] == "a": continue print(item)

Let me know where I'm going wrong. Thanks

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

1 Answer

Hey GURUPRASAD! Couple of things here, on line 3, your saying if "items[0] == "a". But this is looking at the entire list. You should be looking at the individual word. So instead say if item[0] == "a". Secondly you havent included the print item in the for loop, meaning it will just print whatever was at the last place in the items list. Your code should look like this:

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

Hope this helps!

Worked perfectly!Thanks a lot Behar. (The indenting is meant to drive people up the wall it seems. I've done a bit of Ruby and Swift, they are not that particular)

Haha yup python is very serious about its indentation! You can mark the question as solved by sellecting a "best answer"