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 trialSandeep Krishnan
9,730 PointsI 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)
def loopy(items):
for i in items:
if i.index(0) == "a":
break
continue
else:
print(i)
Sandeep Krishnan
9,730 Pointsdef loopy(items): for i in items: if i[0] == 'a': continue print(item)
8 Answers
Frank Campos
4,175 Pointsdef 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.
Felipe Lozano
2,316 PointsI tried this, and it gives me an int error
uchenna kamalu
1,091 PointsThis 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.
Alexander Davison
65,469 PointsThumbs 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
Sandeep Krishnan
9,730 Pointsthanks Alexander
Alexander Davison
65,469 PointsYou are welcome :)
micram1001
33,833 PointsFirst 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
timoleodilo
1,438 Pointsits 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
1,875 PointsThis 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
533 Pointsdef 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.
Jesse Mensah
1,759 Pointsam also stuck on the challenge can someone help me
Edwin Chan
7,371 PointsThis is my answer
def loopy(items): # Code goes here for item in items: if item[0] == 'a': continue else: print(item)
Cristian Batista
265 PointsCan someone help me on this one
Sandeep Krishnan
9,730 PointsSandeep Krishnan
9,730 Pointshere 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".