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

Python Basics Challenge - Continue

I'm having a lot of trouble trying to figure this exercise out - I would appreciate some assistance - Here is my code thus far:

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

AND

Here is the exercise I'm working on:

Same idea as the last one. My loopy function needs to skip an item this time, though. Loop through each item in items again. If the character at index 0 of the current item is the letter "a", continue to the next one. Otherwise, print out the current member. Example: ["abc", "xyz"] will just print "xyz".

I tried indenting continue, and I keep getting this message: "Str object is not callable" - So, I erase the indent, and that still doesn't work - I've also tried several other approaches, but I just don't know what I'm missing...

3 Answers

Steven Parker
Steven Parker
231,269 Points

You're close, but I see a few issues:

  • indexing is done with brackets :point_right:[]:point_left:, not parentheses :point_right:():point_left:
  • anything inside a loop must be indented further than the for statement itself
  • any conditionally-executed statements must be indented further than the if statement itself

Thank you for your help everyone - It was much appreciated... P :)

Alejandro Byrne
Alejandro Byrne
2,562 Points

Your for loop has to be for item in items, not i in items.

Actually, the name of the "temporary" variable used in a loop doesn't matter.

It can be whatever your heart desires, as long as it is a Valid Python name.

Just to recap:

  • Variables must have only letters, numbers, and underscores _
  • Variable names can't start with a number (or Python will think it is a number)
  • No special characters other than underscores! (for example, #%^$(*& are all not allowed. Keep in mind this includes spaces!)
  • No dashes (- represent a dash)! Python will think you are trying to do subtraction!