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

Shamushideen Sule
PLUS
Shamushideen Sule
Courses Plus Student 2,509 Points

Second shopping list

My loopy function needs to skip an item. Loop through each item in items. If the character at index 0 of the current item is the letter "a", continue to the next one. Otherwise, print out the current member. Example: ["abc", "xyz"] will just print "xyz".

My solution: def loopy(items): items = ["abc", "xyz"] for item in items: if item[0] == "a": continue print(item) else: break print(item)

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

1 Answer

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

You are very close.

  • you should not create a variable named items - items would be the argument.
  • also, you would want to check if item[0] == 'a' instead of checking item[0] == 'abc'
def loopy(items):
    # loop through items
    for item in items:
        # if character at [0] == 'a'
        if item[0] == 'a':
            # then continue
            continue
        # else print item
        print(item)