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 trial

Python Python Basics (2015) Shopping List App Continue

Waleed Aljarman
PLUS
Waleed Aljarman
Courses Plus Student 947 Points

My 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 ?

breaks.py
def loopy(items):
    # Code goes here
    while True :
        if items[0] == "a": 
            continue 
        else : 
            print(items)  

2 Answers

Sorry 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.

Your 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
Waleed Aljarman
Courses Plus Student 947 Points

can you explain more, i didn't understand the x part.