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

Daniel McCallum
Daniel McCallum
648 Points

Continue

Hi, the example problem is:

My loopy function needs to skip an item this time, though. 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 every member of items.

I'm struggling to find the solution, please help!

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

2 Answers

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey there Daniel,

you have a few problems in your code. Firstly you have to put a colon after your if's condition, secondly to get the current item's value at the index of 0 you should write item[0] .

Besides that you have both a break and a continue in your if block now which doesn't make sense because only the first one will be executed and because the first keyword you're using is break the loop will stop if an item's index 0 is the letter a.

The last thing you have to fix is that you should print out the current item but you're printing out the whole items list right now. So you have to write item instead of items.

This is a working example:

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

I hope that helps, if you have further questions feel free to ask! :)

Daniel McCallum
Daniel McCallum
648 Points

Thanks for your help Tobais much appreciated, thanks!