List slices PRO exercise problem | Sololearn: Learn to code for FREE!


List slices PRO exercise problem

Why is the output 2 and not 42? Can someone please explain this to me? ------------------- x = input() elements = x.split() print(x[:-2:-1]) ------------------- input: [42] output: 2

4/27/2021 2:04:27 PM


3 Answers

New Answer


some tutorial


in indexing Im sure you know you have your [start:stop:step] if x is a list of two items, then print(x[:-2:-1]) means: print a list of all the values in the list reversed (-1), up to but not including the second to last value in the original list (-2).


Thank you! :D