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 trialBen Hedgepeth
Python Web Development Techdegree Student 10,287 PointsUsing Continue while iterating a list
I'm not clear on what I'm doing wrong with my code. I'm testing whether the first character of each item in the list starts with 'a'
but the challenge isn't passing.
def loopy(items):
for item in items:
if item.index("a") == 0:
continue
else:
print(item)
2 Answers
Antonio De Rose
20,885 Pointsdef loopy(items):
for item in items:
if item.index("a") == 0: #this will actually return, the index, had there been an element with the value "a"
#that too you cannot use "==", if at all to find the index of an element of "a" - item.index("a")
#close, give it a try, hint - square bracket
continue
else:
print(item)
Jennifer Nordell
Treehouse TeacherHi there! Remember that if the substring is not found at all it will raise an exception and the function will terminate. So if we send in an item like "test", then this will fail. There is another way to check if the first letter is an "a". Strings can have the individual characters accessed through subscripting just like the items in a list.
Here's an example:
my_string = "Treehouse"
print(my_string[4])
This would print the letter "h". I think you can get it with these hints, but let me know if you're still stuck!