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

Kaci Jenkins
Kaci Jenkins
860 Points

loopy function needs to skip an item...?

Not sure what I'm doing wrong. Is there a different way to reference index 0? Do I not need to call upon it so literally?

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

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Kaci,

You're on the right track, but I think may be taking the instructions a bit too literal. Your if statement does need to check the value a the 0 index of the iterable being looped through, just not the literal "index = 0". With the for loop, each item will be checked and stored in the temporary variable item, and the if statement is going to check the value of the 0 index of item.
So, all your 'structure' is correct, :thumbsup: you just need to adjust what is being checked. Remember, to check the index, you use square brackets to access the specific index, so it would be like variable[index].

I have provided the corrected code to illustrate this for you.

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

Keep Coding! :) :dizzy:

Kaci Jenkins
Kaci Jenkins
860 Points

awesome, thanks! I feel so compelled to include an "else:" before the print() but it usually kicks the answer back. For me, it just flows better. Would it cause actual issues or is it just their preference that I don't use it?