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

Python Basics

I am having trouble solving this question can someone please explain me what i should do ? my original code is

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

breaks.py
def loopy(items):
    # Code goes here

2 Answers

Žiga Pregelj
Žiga Pregelj
18,126 Points

You're almost there, only change continue with pass and it will work ;)

def loopy(items):
    # Code goes here
    for item in items:
        if item[0] == "a":
            pass
        else:
            print(item)

Oh, and you can choose first index only with these brackets and number inside [0], but it should work with your way too.

Hey thanks for the help. I found it a bit hard to understand the difference between pass and continue cause i tested it out and it gives back the same results. What i understood is that continue only works in a for or while loop, and pass works in a more general purpose. If you could provide me some examples would be great.

Žiga Pregelj
Žiga Pregelj
18,126 Points

I checked it out and you have to use CONTINUE in this case, because PASS doesn't do nothing, it just checks the first item's index and goes on to else, while continue makes that loop go through all items and checks if their first letter is "a".

I think that this challenge shouldn't work with pass, maybe Kenneth forgot to turn off this option :D .

Here is a little bit deeper explanation:

http://stackoverflow.com/questions/9483979/is-there-a-different-between-continue-and-pass-in-a-for-loop-in-python

And code with continue

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