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 trialPaul Walker
3,370 PointsChallenge: Make loopy function skip an item.
I cannot figure out this challenge. I've tried so many iterations of my code posted below, but nothing works and I cannot seem to figure out how to accomplish it.
"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"."
def loopy(items):
for item in items:
if item == "a".index(0):
continue
else:
print(item)
2 Answers
nakalkucing
12,964 PointsYou need your code to say if the item in the oneth place is equal to "a" continue. What your code says right now is: if "a" is at the index of zero continue. Hope this helps, Nakal
Paul Walker
3,370 PointsThank you so much, nakalkucing! You explanation cleared it up. I was going by specific index on the list instead of thinking about how many items are in the list. Here was the end result:
def loopy(items):
for item in items:
if item[0] == "a":
continue
else:
print(item)
nakalkucing
12,964 PointsThanks! You did a great job! :) I'm glad I could help you.