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

Jean Apolo
Jean Apolo
3,494 Points

I am confused on the context of the python Shopping List challenge question

Here are the details of the specific challenge question: "Same idea as the last one. My loopy function needs to skip an item this time, though. Loop through every item in items. If the current item's index 0 is the letter "a", continue to the next one. Otherwise, print out every member of items."

I am confused about whether I should care about specifically index 0 or any "current" index that has only the letter "a" in general as then loopy function goes though the for loop? This function prints out every member of items except the items that have only the letter "a" but it did not like it. Is it the 0th index or any current index in general that the program needs to skip if it encounters the only letter "a"? The instructions for the second sentence of what this particular challenge task is ambiguous and needs more clarification.

breaks.py
def loopy(items): 
    # Code goes here 
          for item in items: #Goes though items list in loopy argument 
              if items[0] == "a": #Skip printing elements that are exactly "a" 
                    continue 
              else: 
                    print(item) #Print everything else other than elements containing "a".
Boris Ivan Barreto
Boris Ivan Barreto
6,838 Points

Hi Jean,

Here you can find the way to sort out this challenge

def loopy(items):
    for item in items:
      if item[0] != "a": # This way you will skip the item that starts with "a" and print the items required
        print(item)

1 Answer

Gianmarco Mazzoran
Gianmarco Mazzoran
22,076 Points

Hi,

you're really close!

You need only to select item and not items in your if statement:

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