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

siva sanka
siva sanka
4,099 Points

help me regarding this code

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
    if items(0)=='a':
        continue
    else:
        print(items)

1 Answer

Hey siva! Couple of things, one is that you should loop through ever item in the list "items". You should use a for loop for this. Secondly is that your not looking at indexes correctly, when looking at an index we dont use () we use []. If you dont know for loops i recommend you rewatch the video about them, as they are quite important in just about any programming language. For your code:

def loopy(items):
    # Code goes here
    for item in items: # Here were doing a for loop which will check ever "item" in the list "items"
        if item[0]=='a': #Here were checking if the current items has the string "a" at index value 0
            continue
        else:
            print(item) #Here were printing the item, you dont want to print the entire list "items", just the item