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

Unable to pass the challenge

I am unable to pass these challenge with below code, though I am getting right output on my python shell.

breaks.py
def loopy(items):
    # Code goes here
    for idx, item in enumerate(items):
        if idx == 0 and 'a' in item:
            continue
        else:
            print(item)

2 Answers

I seems you may have too much going on here. 'items' is already iterable so the code doesn't need too much

def loopy(items):
    # Code goes here
    for x in items:
        if 'a' in x:
            continue
        else:
            print(x)

Thank you, Christopher.

This worked to pass the challenge but I tested it in work spaces and it skips all string items that have an 'a' anywhere in the sting not just at the start. Based on the goal it should only skip the ones that start it. What would need to be added to make that work

Have a look at the wording of the challenge If the character at index 0 of the current item is the letter "a", continue to the next one..

In your code, you are looking for "a" as any letter in the first item, where you should be continuing on any item that starts with "a", for example ["cba", "abc", "afg"] will just print "cba" as a is not the first letter here as it is in the other 2.

Thank you for explaining it to me.