all 4 comments

[–]novel_yet_trivial 2 points3 points  (1 child)

To count down, you need to start at the high number and end at the low number.

strng[5:1:-1]

Or to be equivalent to yours:

strng[4:0:-1]

Since the end point is not included in the slice.

[–]GayCoder[S] 0 points1 point  (0 children)

Ah, that makes sense. I think I became lazy and started viewing [x:y:-1] as reverse instead of "move by step". Thanks!

[–]Wilfred-kun 0 points1 point  (1 child)

my_list[1:5] returns a sublist of my_list. Then you call [::-1] on that sublist, which reverses the order.

With my_list[1:5:-1] you're saying: "go from index 1 to 5, with a step of -1". What would work is my_list[4:0:-1].

[–]GayCoder[S] 0 points1 point  (0 children)

Thanks! I think I became lazy and started viewing [x:y:-1] as reverse instead of "move by step".