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 trialWaleed Aljarman
Courses Plus Student 947 PointsMy code took to long to run. What to do ?
it says that if the item start with an "a" i should skip it. should i use other methods to make the code shorter, or did i make a mistake ?
def loopy(items):
# Code goes here
while True :
if items[0] == "a":
continue
else :
print(items)
2 Answers
William Harrison
9,585 PointsSorry I just used x as a random variable. I rework what I did here.
def loopy(items):
# Code goes here
for item in items:
if item[0] == "a":
continue
else :
print(item)
I just replaced the while statement, with the for statement. Each cycle will put one element of the list into the item variable.
William Harrison
9,585 PointsYour while does not end, due to it always being set to True. Also the code never cycles through items. I would use a FOR loop instead of the WHILE. Something like -- for x in items: -- Then test for x[0] == 'a'
Waleed Aljarman
Courses Plus Student 947 Pointscan you explain more, i didn't understand the x part.
Waleed Aljarman
Courses Plus Student 947 PointsWaleed Aljarman
Courses Plus Student 947 PointsNow i get it, thanks a lot.