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 trialRebecca Barnett
483 PointsStruggling with python loops and indexes
I am unsure if I am even on the right track with this. I keep trying out my code in workspaces so I can get better feedback on what's wrong with my code and it keeps saying there's a syntax error near the "a" but I'm not sure that that's right; at least, I don't think that's the only thing that's wrong.
def loopy(items):
# Code goes here
for item in loopy:
if item.index[0] == 'a'
continue
else:
print(item)
1 Answer
Keifer Joedicker
5,869 PointsThe 'a' would need a colon but there are a few more things you should look at.
You want to loop through what ever data is provided through the items argument in the function.
to do so:
def loopy(items):
for item in items:
Your referencing the first index on each particular item you loop through so you can get away with this.
def loop(items):
for item in items:
if item[0] == 'a':
continue
Finally your code can pass looking like this:
def loopy(items):
for item in items:
if item[0] == 'a':
continue
print(items)
Rebecca Barnett
483 PointsRebecca Barnett
483 PointsThat helped tremendously! Thank you!