We may be able to get away with just not printing the X’s, rather than going through all the trouble of deleting them and them making a new string!
Remember, to start a list slice at the end of a string and traverse to the beginning, we simply write nothing for the start and end indexes, and then make our stride index negative by the amount we want to traverse at each step.
Doing my_string[::-3] would give us every third character in my_string. The code for getting every other character is very similar!
Because in the correct answer they are going over the whole list and taking every second letter starting going backwards (due to the - Infront of the 2).
In yours you are taking the items in the list from the last item and tried to then go to the second item (the first would be 0) but the step you’ve given it is 2 forwards, not backwards. So from the last item it will try take every second item going up the list until it gets to the start of the list, obviously that can’t happen because it is going the wrong way, you need a - in front of the 2. But now because you want the whole list anyway you don’t need a start and end index. So you get back to [::-2].
I’ve gotta say your comments are most insiteful (a word?) and helpful to a guy trying to learn this challenging stuff. You and 1 other person - can’t remember his icon - I religiously read & always take away something meaningful.
I don’t know if you’re a professional programmer or a top-flight amateur, but you can do more in 4 lines of code than i can in 10!
Thanks & cheers,
Chuck
I have a problem with this exercise, when I started the code I was given to start off with was my answer to the previous exercise, and when I checked the soution it was supposed to start with the list called ‘garbled’ and then the hidden message. I did the code correctly but when I ran my code, it said it was wrong even though I had done it correctly. Resetting the exercise did not help either. Not sure what is going on and why the code is different to what its supposed to be
Thanks