List Slicing


#1

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

not sure what is the issue ?

Error : Oops, try again. Your message doesn't look quite right; instead of "IX XaXmX XtXhXeX XsXeXcXrXeXtX XmXeXsXsXaXgXeX!", it should be "I am the secret message!"


#2

You need to assign the final result of the slicing operation to message, then display it.

You can perform the slicing operation in a single statement instead of two.


#3

what do you mean ? it's already assigned to message ?


#4

got you, understood. I did it and it worked

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


#5

If the final result were assigned to message, then why would it be necessary to do additional slicing here? ...

print(message[::2])

#6

Thank you so much and headin to the next level lol. Thank's again


#7

No problem; enjoy the next level. :smile:.


#8

just for your info: you can do the two different slices together

message = garbled[::-2]

3rd value is negativ (=backwards) in steps of 2 (skipping the "X")


#9