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

Bapi Roy
Bapi Roy
14,237 Points

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

Christopher Janke
Christopher Janke
11,054 Points

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)
Bapi Roy
Bapi Roy
14,237 Points

Thank you, Christopher.

Torrey Bley
Torrey Bley
482 Points

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

Christopher Shaw
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 Points

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.

Bapi Roy
Bapi Roy
14,237 Points

Thank you for explaining it to me.