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 trialIan Maina
4,571 PointsCan't seem to get anywhere with this challenge. Any tips?
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):
# Code goes here
for item in items:
if item.index([1]) == 'a':
continue
else:
print(item)
1 Answer
Ted Dunn
43,783 PointsThe problem is with your if condition, the index method returns a value which is the integer value of the index where the supplied substring begins. Thus, you are comparing an integer to a string ("a") and it will never evaluate as True.
I would suggest the following:
for item in items:
if item[0] == "a":
continue
else:
print(item)
This code is referring to the letter at the index of zero for the item begin examined (item[0]) and comparing it to the letter "a". Thus, you are comparing a string (letter at index 0 of item) to a string ("a").