9/18 Reversing A List


#1

Why does "backwards=my_list[10:0:-1]" not work? Can someone explain why?


#2

Your range goes from the start number (10) to (but not including!!!) your stop number (0). To fix this you could write [10::-1] and it will go from 10 until it reaches the end (in this case 0) or even [::-1] for the entire range.


#3

How about if I did it "backwards=my_list[10:-1:-1]?


#4

You can't use -1 for an index


#5

But how then does doing "backwards=[::-1]" accomplish this without assuming that the end position is -1?


#6

backwards=my_list[::-1]
print backwards