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

python basics breaks.py

I can't seem to figure this one out, please help!

breaks.py
def loopy(items):
    for item in items:
      if item.index(0) == 'a':
        continue
      print(item)

3 Answers

Luke Buśk
Luke Buśk
21,598 Points

use item[0] instead of item.index(0) and it will work.

Stopped learning Python long time ago but If i remember corectly by using item.index(0) You are returning the position of 0 in the array (or an error if it's not found) - in short You are looking up what is the index/position of 0 in given array.

By using item[0] You are pointing at the first item in the array and asking if it's equal to "a".

Thank you sir! could I use item.index("a") == 0

?

Luke Buśk
Luke Buśk
21,598 Points

Edited my answer to explain it a little more.

And no, it won't work.

remove the .index as well since you do not need it.

Please review the code below:

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