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 trialoshayne anderson
839 Pointspython pass
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".
def loopy(items):
# Code goes here
a = a[0]
for a in items:
if a == 'a':
pass
else:
continue
2 Answers
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou can drop the a=a[0] line and just directly compare a, your loop variable, sliced to just the first letter, so it would be if a[0] == 'a'. then instead of pass you need continue, to continue to the next item if the first letter of the item is 'a'. the else needs to hold the print statement, since it wants you to print elements that don't start with 'a'.
Modou Sawo
13,141 PointsHi Oshayne,
Do the solution step by step, and you'll find it easy. Firstly, Make sure your code is inside the function (meaning, indent it - see where it says # code goes here). Okay.
So the problem is asking you to loop through every item in items using a for loop. Thus you do:
def loopy(items):
for item in items: # notice the new line is indented
# now add the if condition like you did, you indented that one, NICE!
if item[0] == "a":
continue # It's better to write continue, pass is mostly used when u create a function w/o anything in it
else:
print(item)
Key thing to remember here is, you're asked to write a for loop to loop through each ITEM in ITEMS, and to create an if-else statement to query through the ITEMS, in order to neglect only the first/zero index item (IF it's equal to "a").