List Slicing


My code works fine, but I want to encode the message in the reversal way.
It's "I am the secret message!"
I want to add "X" after every letter to be like the origin:
"!XeXgXaXsXsXeXmX XtXeXrXcXeXsX XeXhXtX XmXaX XI"

garbled = "!XeXgXaXsXsXeXmX XtXeXrXcXeXsX XeXhXtX XmXaX XI"

end = len(garbled) + 1
message = garbled[end::-2]
print message

message = "I am the secret message!"
mod1 = message[len(message) + 1::-1]


What you are trying to do cannot be done with list slicing, alone. It will take a loop of sorts.

print ''.join(['X' + x for x in "I am the secret message!"[::-1]])[1:]

# !XeXgXaXsXsXeXmX XtXeXrXcXeXsX XeXhXtX XmXaX XI


Got it. Thank u so much.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.