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 trialJohn Cuddihy
5,493 PointsUsing the index of a string
How to set the Index 0 in 'Loop through every item in items. If the current item's index 0 is the letter "a", continue to the next one. Otherwise, print out the current member.'
def loopy(items):
for item in items:
if item.index[0] =="a":
continue
else:
print(item)
2 Answers
Steven Parker
231,269 PointsYou almost have it. But .index is a method used for finding an index for certain contents, you won't need that here.
You just need to get the first letter of the item (index of 0), using the indexing operator: [] (brackets).
if item[0] == "a":
Cindy Lea
Courses Plus Student 6,497 PointsYou need to change your for statement so it loops until it gets to last item. You need a function that determines how many items are in array then make it part of for statement.
Steven Parker
231,269 PointsActually, he for...in statement he has already handles that nicely, without needing to keep track of the count of items.