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

Christian Trolle
Christian Trolle
508 Points

Skipping item in list if the index 0 in a word is =='a'

The question is "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"."

I have two issue.

  1. how do is identify the index 0 in a word ? so far is have said item[so] =='a'
  2. how do I skip the item if the if-statement is fulfilled? I have used: if items[0] =='a': next(item)

I hope someone can help me out :)

breaks.py
def loopy(items):
    # Code goes here
    for item in items
        if items[0] =='a':
            next(item)
        print(item)

3 Answers

Abdishakur Hassan
Abdishakur Hassan
3,585 Points

Hi. You are almost there. You have all the necessary bits of code. Instead of next (item). Just write continue. your code should look like this.

def loopy(items):
    # Code goes here
    for item in items:
        if item[0] == 'a':
            continue
        print(item)
          ```
valerakushnir
valerakushnir
2,265 Points

I don't quite grasp what's happening in here:

if items [0] == 'a':
            continue

Can someone explain in plain English? :)