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

Tariq Kfaery
Tariq Kfaery
956 Points

what is wrong with my code here?

Same idea as the last one. My loopy function needs to skip an item this time, though. Loop through each item in items again. If the character at index 0 of the current item is the letter "a", continue to the next one. Otherwise, print out the current member. Example: ["abc", "xyz"] will just print "xyz".

breaks.py
def loopy(items):
    # Code goes here
    x = []
    for x in items:
        x.append(items)
        if x.index(0) == "a":
            continue
        else:
            print x

3 Answers

Stuart Wright
Stuart Wright
41,120 Points

Here are some hints to get you started:

  • The challenge doesn't ask you to create a new list and append items to it. You can delete both of these lines. You only need to check whether or not each item begins with 'a', and print it out if not.
  • The correct syntax for getting the first character of a string is x[0] (where x is the string).
  • The print function needs (), so correct syntax is print(x).

lets go through the code and question, with couple of things to remember:

string can be treated as a List. so in string="Abrakadabra", string[0]='A', string[1]='b'...so on.

def loopy(items):
    # Code goes here
    x = []
    #creating an empty list
    for x in items:
        #for each string in items
        x.append(items)
        #Appending whole list of items into the list x. Now x is list of list.
        if x.index(0) == "a":
            #checking if index of '0' in the list is a
            continue
        else:
            #trying to print x, which is an array.[treehouse uses python3.0 so print function is print().
            print x

Lets see what we need to do now:

def loopy(items):
    # Code goes here
    #Loop through each item in items 
    for item in items:
        #If the character at index 0 of the current item is the letter "a", continue
        if item[0] == 'a':
            continue;
        else:
            #else print the item
            print(item);

Hope this helps.