10: 17. List slicing


#1



10: 17. List slicing


garbled = "!XeXgXaXsXsXeXmX XtXeXrXcXeXsX XeXhXtX XmXaX XI"

message = garbled[-1::2]
print message

This returns just the last letter ("I"). So I know the syntax works, but for all other attempts, e.g.:

garbled = "!XeXgXaXsXsXeXmX XtXeXrXcXeXsX XeXhXtX XmXaX XI"

message = garbled[-1:1:2]
print message

I get result "", which from a bit of reading I deduced is basically just an error. I get this result from almost all other various number combinations


#2

here:

message = garbled[-1::2]

-1 is your start value, which means you start at the right hand side, then you increase by 2 (+2), which means you will go even further to the right hand side, where there is nothing anymore


#3

Ahhhh...so stupidly obvious once you know, I've been banging my head against that one for ages now


#4

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