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 trialEd B
Courses Plus Student 3,973 PointsCode not working
This function works in Workspaces when I pass it a list, but it doesn't work for this challenge. Not sure what is wrong with it.
def loopy(items):
x = 0
while x < len(items):
if items[x] == "a":
x += 1
continue
else:
print(items[x])
x += 1
2 Answers
Cindy Lea
Courses Plus Student 6,497 PointsYou can do this using a for or if condition:
def loopy(items):
for item in items:
if item[0] == "a":
continue
else:
print(item)
'''
Steven Parker
231,269 PointsJeremy's point (and Cindy's) that more compact code could satisfy this challenge is valid, but it doesn't address your issue.
You're comparing each item with "a" instead of just the element at index 0.
Line 4 should probably be like this:
if items[x][0] == "a":
Other than that, your logic is sound, even if it's not the most compact. Don't worry, you'll pick those skills up with practice.
Jeremy Hill
29,567 PointsJeremy Hill
29,567 PointsThe code above is over complicated for what the challenge is wanting. You can do a for loop that loops through each item in items and then check to see if the first index is equal to the letter 'a' and then print if it's not.