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

Ed B
PLUS
Ed B
Courses Plus Student 3,973 Points

Code not working

This function works in Workspaces when I pass it a list, but it doesn't work for this challenge. Not sure what is wrong with it.

breaks.py
def loopy(items):
    x = 0
    while x < len(items):
        if items[x] == "a":
            x += 1
            continue
        else:
            print(items[x])
            x += 1

The code above is over complicated for what the challenge is wanting. You can do a for loop that loops through each item in items and then check to see if the first index is equal to the letter 'a' and then print if it's not.

2 Answers

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

You can do this using a for or if condition:

def loopy(items):
  for item in items:
    if item[0] == "a":
      continue
    else:
      print(item)
'''
Steven Parker
Steven Parker
231,269 Points

Jeremy's point (and Cindy's) that more compact code could satisfy this challenge is valid, but it doesn't address your issue.

:point_right: You're comparing each item with "a" instead of just the element at index 0.

Line 4 should probably be like this:

        if items[x][0] == "a":

Other than that, your logic is sound, even if it's not the most compact. Don't worry, you'll pick those skills up with practice.