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 trialShady Habashy
2,139 PointsHi there I can't solve this Challenge
this is my code
if "a" in items[0]: del items[0] for item in items: print(items)
don't know why ti is not working ?
def loopy(items):
# Code goes here
if "a" in items[0]:
del items[0]
for item in items:
print(items)
1 Answer
Katie Wood
19,141 PointsHello there -
The wording on this one is a little bit tricky - currently, your code will check whether the first item in "items" has an "a" in it - instead, the challenge is asking you to loop through the whole "items" list and skip any value that has "a" as the first letter, meaning index 0 of that specific item.
It would look similar to what you have, so let's go through it in a few steps. First, we want everything to be inside the 'for' loop, so I'm going to take what you have and remove everything outside the loop - we'll add the 'a' part back in a second.
def loopy(items):
# Code goes here
for item in items:
print(item)
So now we have a loop that will print each item in the list. Now we just need it to skip the item if 'a' is the first letter, so we need a conditional:
def loopy(items):
# Code goes here
for item in items:
if(item[0] == 'a'):
continue
else:
print(item)
So, for each item, it will check if the first letter is 'a', and skip it if so. If not, it will print that item.
Hope this helps!