How can I remove the X’s from the garbled string?


#1

Question

How can I remove the X’s from the garbled string?

Answer

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!


FAQ: Learn Python - Advanced Topics in Python - List Slicing