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 trialAaron Fornkohl
3,188 PointsCant get past code challenge
I can figure out what I am doing wrong. Can someone explain why this is not working?
Same idea as the last one. My loopy function needs to skip an item this time, though. 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 every member of items.
def loopy(items):
for item in items:
if item.index('a') == 0:
continue
else:
print(item)
1 Answer
Seth Reece
32,867 PointsHi Aaron,
You are close, to check the first letter in a string, the index is 0. Indexes are stated using square brackets. You want to use:
if item[0] == 'a':
continue
Aaron Fornkohl
3,188 PointsAaron Fornkohl
3,188 PointsUgh, THANKS!
Tyler Amend
2,236 PointsTyler Amend
2,236 PointsSeth I have a question. I know this is an old post, but I was having an issue with this too and your code helped me get past it. I'm confused as to why you're referencing item as index 0 when the list is considered "items"? It would make sense to me from VBA atleast that in order to test item in index 0 you'd test the list for [0] rather than testing the item itself with a position.
Seth Reece
32,867 PointsSeth Reece
32,867 PointsHi Tyler,
Strings also have indexes in Python. This challenge is asking to loop through a list of strings and check the first letter (index 0) in each string and compare to "a".