Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Shopping List App Continue

Carlos Parra
Carlos Parra
792 Points

Need help with loopy function. My code works in Workspaces, i don't understand why, i can't pass the challenge.

Not much to say, it works. Here is the code i tried on Workspaces.

List = ['apples', 'bananas']

def loopy(items): for item in items: if item.index('a') == 0: continue print(item)

loopy(List)

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

2 Answers

Steven Parker
Steven Parker
216,012 Points

:point_right: It "works" with that particular test data, but the challenge is going to test it with other data (try including a word in your test list that has no 'a' in it).

The challenge says to check If the current item's index 0 is the letter "a", but you seem to be checking if the index of 'a' is the number 0.

Also remember that the operator for simple indexing is a pair of brackets [].

Carlos Parra
Carlos Parra
792 Points

Sigh, yeah, you're right. But it is basically the same in the real world i bet. i just switched up how it was done. Thanks