Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Shopping List App Continue

Virochaan Ravi
Virochaan Ravi
6,940 Points

Don't Understand CHallenge

Please help me understand and see the code involved in this challenge

breaks.py
def loopy(items):
    # Code goes here

2 Answers

andren
andren
28,521 Points

This challenge is actually quite similar to the earlier break challenge. The only difference is that you have to check a specific letter of the item, rather than the item itself. And that you have to use the continue keyword instead of the break keyword.

The continue keyword simply makes the loop skip an item. Pulling out a specific letter in a string can be done in the same way you pull out a specific item in a list by simply using bracket notation.

Here is an example of the solution:

def loopy(items):
    for item in items: # Loop though the items list
        if item[0] == "a": # Pull out the first letter of the item string (indexes start at 0)
            continue # Continue if the first letter is "a"
        print(item) # Print the item if that is not the case

If there is something you'd like more details on, or if you are still confused then feel free to ask me follow up questions, I'd be happy to answer anything I can.

#they are asking you to loop  the argument 'items '
#if the first character is 'a' pass, always the first character will at the index 0
#when It find an "a" just pass it
def loopy(items):
    for item in items:
        if item[0] == 'a':
            pass
        else:
            print(item)