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 trialBENJAMIN DAVIS-BLOOM
864 Pointspython basics breaks.py
I can't seem to figure this one out, please help!
def loopy(items):
for item in items:
if item.index(0) == 'a':
continue
print(item)
3 Answers
Luke Buśk
21,598 Pointsuse item[0] instead of item.index(0) and it will work.
Stopped learning Python long time ago but If i remember corectly by using item.index(0) You are returning the position of 0 in the array (or an error if it's not found) - in short You are looking up what is the index/position of 0 in given array.
By using item[0] You are pointing at the first item in the array and asking if it's equal to "a".
BENJAMIN DAVIS-BLOOM
864 PointsThank you sir! could I use item.index("a") == 0
?
Luke Buśk
21,598 PointsEdited my answer to explain it a little more.
And no, it won't work.
Michael Rasay
2,860 Pointsremove the .index as well since you do not need it.
Please review the code below:
def loopy(items): # Code goes here for item in items: if item[0] == 'a': continue print(item)