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

SAIADITHYA CUMBULAM
SAIADITHYA CUMBULAM
688 Points

help

def loopy(items): for num in items: if items.index[0] is 'a': continue print(num)

breaks.py
def loopy(items):
        for num in items:
                if items.index[0] is 'a':
                   continue
                print(num)

2 Answers

Your code is the following:

def loopy(items):
        for num in items:
                if items.index[0] is 'a':
                   continue
                print(num)

Your third line in your code has if items.index[0] is 'a': You have "items", and it should be "num". You don't need to use the word .index, the brackets with zero inside is all that is needed. The square brackets are the indexing operator. num[0] returns the first item in the array num. The word "is" will work for the quiz, but I have seen others use "==" instead. The word "is" will return True if two variables point to the same object, == if the objects referred to by the variables are equal. Both of the codes below will work for this quiz.

def loopy(items):
    for num in items:
        if num[0] is 'a':
            continue
        print(num)

or

def loopy(items):
    for num in items:
        if num[0] == 'a':
            continue
        print(num)
Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

In this case, using == is preferred. is should be used when comparing if two objects are literally the same object in memory.

You are welcome!