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

Cameron Buriani
Cameron Buriani
1,113 Points

Im unsure how to properly format, if index (0) == "a"...continue. any resources for this?

here is my best shot at the code:

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

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

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

elif is used with if statements to mean 'else if'. here you are only trying to omit certain items from a list while printing the rest, so you need a for loop like you have, then an if statement inside of that, before you print anything. you want to check your condition, then print only if it is not met. so your elif needs to come after an if - if(something.....action) elif(something else....action).

Cameron Buriani
Cameron Buriani
1,113 Points

james south - deeply appreciate the clarification, that helped illuminate the problem while providing me with a better understanding of the rules that governing functions/loops. Thanks you!