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 trialJean Apolo
3,494 PointsI am confused on the context of the python Shopping List challenge question
Here are the details of the specific challenge question: "Same idea as the last one. My loopy function needs to skip an item this time, though. Loop through every item in items. If the current item's index 0 is the letter "a", continue to the next one. Otherwise, print out every member of items."
I am confused about whether I should care about specifically index 0 or any "current" index that has only the letter "a" in general as then loopy function goes though the for loop? This function prints out every member of items except the items that have only the letter "a" but it did not like it. Is it the 0th index or any current index in general that the program needs to skip if it encounters the only letter "a"? The instructions for the second sentence of what this particular challenge task is ambiguous and needs more clarification.
def loopy(items):
# Code goes here
for item in items: #Goes though items list in loopy argument
if items[0] == "a": #Skip printing elements that are exactly "a"
continue
else:
print(item) #Print everything else other than elements containing "a".
1 Answer
Gianmarco Mazzoran
22,076 PointsHi,
you're really close!
You need only to select item
and not items
in your if
statement:
def loopy(items):
# Code goes here
for item in items:
if item[0] == "a": # selecting "item"
continue
else:
print(item)
Boris Ivan Barreto
6,838 PointsBoris Ivan Barreto
6,838 PointsHi Jean,
Here you can find the way to sort out this challenge