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

Kyle Sass
Kyle Sass
902 Points

I need to skip the item that has 'a' at index 0. I am unable to complete it. Please help.

Here are the instructions: Same idea as the last one. My loopy function needs to skip an item this time, though. Loop through each item in items again. 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".

breaks.py
def loopy(items):
    # Code goes here
    for item in items:
        if item.index[0] == 'a'
            break
            continue

2 Answers

AJ Salmon
AJ Salmon
5,675 Points

Hey Kyle,

The way Kim did it would probably be the ideal way to do it. However, I do want to point out that breaking breaks out of the loop completely, while continuing simply skips over the current item. A break shouldn't come before a continue :) Alternatively, you could write it like this:

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

No break needed, just a continue. Again, it's simpler and easier to read when done the way the Kim did the challenge, but there are almost always different ways to solve the same problem!

Kyle Sass
Kyle Sass
902 Points

Thanks for your help!

Kim Kauppinen
Kim Kauppinen
8,655 Points

I did it like this. It prints the current item if the first character IS NOT "a".

def loopy(items):
    for item in items:
        if item[0] != 'a':
            print(item)
Kyle Sass
Kyle Sass
902 Points

Thanks, for your help!