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

Sandeep Krishnan
Sandeep Krishnan
9,730 Points

I am stuck at challenge Task one in Python - To do list making

i tried the following code, in-vain. Please help me.

def loopy(items): for i in items:
if i.index(0) == "a":
break
continue else:
print(i)

breaks.py
  def loopy(items):
    for i in items:       
        if i.index(0) == "a":  
            break  
            continue 
        else:            
            print(i)      
Sandeep Krishnan
Sandeep Krishnan
9,730 Points

here is the full problem -

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".

Sandeep Krishnan
Sandeep Krishnan
9,730 Points

def loopy(items): for i in items: if i[0] == 'a': continue print(item)

8 Answers

def loopy(items):
    for loopitems in items:
        if loopitems[0]== "a":
            continue
        else:
            print(loopitems) 

loopy(["abc","xyz","yio","pol"]) 

This code works, I hope this help.

I tried this, and it gives me an int error

uchenna kamalu
uchenna kamalu
1,091 Points

This does work but the question is this right here confuses me "If the character at index 0 of the current item is the letter a" Doesn't this another way of saying,"If the first letter of the current item is a". But in the solution you provided, it it treated as if the first item in the list is a.

Thumbs up! You did great. However, I think you misunderstood the meaning of the .index() function.The .index() function is for retrieving indexes, like in this example (I'm just pretending that I'm in the Python Shell):

>>> my_list = list("abcdefghijklmn")
>>> my_list
["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"]
>>> my_list.index("a")
0
>>> my_list.index(0)
Traceback (most recent call last)
    File "<pyshell#1>", line 1, in <module>
        my_list.index(0)
ValueError: 0 is not in list

As you see, when I tried to get the element using ".index()", I got an value error. To get an element, you must use the square backets []:

>>> my_list[0]
"a"

I hope you can find your error now :)

Good luck! ~Alex

You are welcome :)

First make a for loop

for item in items:

then look for the index of 0 to compare to "a"

if(item[0] == "a"):

then continue

otherwise (else statement)

else:
     print(item)

in the items list

its not going through though. just like it. not sure where the error is:

def loopy(items): for item in items: if (item[0] == 'a'): continue else: print(item)

Brian Friedman
Brian Friedman
1,875 Points

This one was a hard one. I hope seeing the answer will help :)

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

Hunter Nelson
Hunter Nelson
533 Points

def loopy(items): for item in items:
if item[0]=='a': continue else: print(item)

#remember to use the "for item in items" line. Also use the right indent; it looks different in code.

am also stuck on the challenge can someone help me

Edwin Chan
Edwin Chan
7,371 Points

This is my answer

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

Cristian Batista
Cristian Batista
265 Points

Can someone help me on this one