17. List Slicing - Advanced Question


#1

Hey everyone.

I got it, the solution is:

garbled = "!XeXgXaXsXsXeXmX XtXeXrXcXeXsX XeXhXtX XmXaX XI"
message = garbled [::-2]
print message

The thing is: I got that by randomly trying stuff. I didn't see that every second letter is an "X". I thought the challenge was not only to read the statement backwards while just printing every second letter, but to print the statement backwards while deleting every X.

Now the job is done, but I still wonder how I can do what I thought I should do. So, can anyone explain how I could get the reversed message without X's?


#2

And I just saw the next task ... nevermind. xD


#3

garbled.translate(None, 'X')
removes all 'X'


#4

thanks @boardrockstar90452 ...never thought like that before..nice sharing..:grin:


#14