Need help with this please
Hi, I wrestled with this for a while but it only seems to work a bit. Meaning, the following code does skips the 0th element and prints xyz if the array is items = ["abc","xyz" ] but if the list has more elements it skips all elements and prints the last one. def loopy(items): for item in items: if items == "a": continue print(item)
Let me know where I'm going wrong. Thanks
def loopy(items): for item in items: if items == "a": continue print(item)
Hey GURUPRASAD! Couple of things here, on line 3, your saying if "items == "a". But this is looking at the entire list. You should be looking at the individual word. So instead say if item == "a". Secondly you havent included the print item in the for loop, meaning it will just print whatever was at the last place in the items list. Your code should look like this:
def loopy(items): for item in items: if item == "a": continue else: print(item)
Hope this helps!