What am I missing here? - slicing


#1

why is the answer middle_third = to_21[7:14] instead of middle_third = to_21[8:15]???
it wants 8-14 inclusive and I thought that when you use slice it will start with the first number and go all the way to but not including the last number. what am I missing here?


11/18: im not sure what i am doing wrong?
#2

Simple answer... zero indexing. The 7 is an index to start at; the 14 is the excluded endpoint, also an index.

1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
                     |  |  |  |  |  |  |
0  1  2  3  4  5  6 [7  8  9 10 11 12 13]14 15 16 17 18 19 20

#3

awe man!!! thanks for the reply. when I read part 3 of that problem I thought ok they want from 8 to 14, so [8:15]. d@mn you Zero index.


#4

8 to 14 are the values in the elements. The slice to select them is [7:14]. Check the second row in the example.


#5

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