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 trialmarvinriley
3,708 PointsShopping List 2 - going wrong.
So I've read and tried to understand this coding challenge but I'm not sure where I'm going wrong. I've looked up the .index and thought I placed it in the right place. Clearly not.
Can any one point me in the right direction.
def loopy(items):
for item in items:
if item.index == "a"
continue
else:
print(item)
1 Answer
markmneimneh
14,132 PointsHello
you are missing : as in
if item.index == "a":
and I suspect you mean to code it as below:
def loopy(items): for item in items: if item == "a": continue else: print(item)
loopy("ababab")
if this answers you question, please make the question as answered.
Thank
Tony Martin
5,570 PointsTony Martin
5,570 PointsI think that .index is a method, meaning you need to call it instead of setting it equal to something if you want to use it, however, I'm not sure that's what you want to use here. .index returns the index where the first instance of the value passed into it was found. Here, we don't really need the index of any value in the list. Instead the instructions ask:
the for loop will then move on to the next item in the items list, and then should check the first character in the first item for 'a' again just like before. wash, rinse, repeat.
So, you'd want to write (if I'm remembering this all correctly):
instead of item.index. I think...
edit: also note that you're missing a colon at the end of your if statement.