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 trialvipin kala
Courses Plus Student 707 Pointsbreaks.py Exercise: Skipping the List item in for loop
Hi Andreas, Thanks for the response. As you said I interpreted this question the same way first time and wrote the code as below. But even this won't work.
def loopy(items):
# Code goes here
if items[0] == 'a':
items.remove('a')
for no in items:
print(no)
3 Answers
Kourosh Raeen
23,733 PointsThe if statement should be inside the loop. If the current item in the loop starts with "a" then you ignore it and continue to the next item. Otherwise, you will print it:
def loopy(items):
for item in items:
if item[0] == "a":
continue
else:
print(item)
franck sanchez henckell
Courses Plus Student 1,404 Pointsi fixed with :
item == "STOP"
print (item)
thnks
Kourosh Raeen
23,733 PointsStill not right. I'm not sure why you're using the string "STOP". You need to check to see if the current item's index 0 is the letter "a". If it is you skip it using the continue keyword, otherwise you print it.
franck sanchez henckell
Courses Plus Student 1,404 Pointsdef loopy(items): for item in items: if item == 'STOP': break else: print item
Kourosh Raeen
23,733 PointsThis is not the right solution.