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

Sergey Mangov
Sergey Mangov
3,651 Points

hi, please help me with the code

def loopy(items): # Code goes here new_item = ("> ") if new_item.index [0] = "a": continue for item in items: print (new_item) loopy(items)

breaks.py
def loopy(items):
    # Code goes here
    new_item = ("> ")
    if new_item.index [0] = "a":
        continue
    for item in items:
        print (new_item)
loopy(items)

4 Answers

Steven Parker
Steven Parker
230,274 Points

:point_right: It looks like you have a few issues here:

  • the word "index" isn't used for indexing, just the brackets (new_item[0]) (index is the name of a function)
  • the test needs to be inside the loop
  • the loop variable name can be item or new_item, but it must be used consistently
  • there won't be any need to assign a variable to a literal string
  • don't call loopy yourself, just define it (the challenge calls it internally)

I'll bet you can get it now without an explicit spoiler.

This is what I did:

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

I've learned over time that sometimes it's best to look at code to see how it is done- if they WANT to learn, they will analyze it and learn from it. When you first sat down to start learning code did you get to look at some code so you could analyze it to know how it was done? A lot of what I learned was not from guess work or racking my brain on how it was done but simply studying other people's code and figuring out why it was done the way it was done.

And just to add one more thought to that: there have been times that I would spend a long time trying to solve a problem and having tried it so many ways and failed that when I finally did have the correct solution I couldn't remember even five minutes later which solution was the one that was successful.