Solutions

List re-order

values = []
values.append(1)
values.append(3)
values.append(5)
print('first time:', values)
values = values[1:]
print('second time:', values)

Will produce the required results.

How Large is a Slice?

The list values[low:high] has high - low elements. For example, values[1:4] has the 3 elements values[1], values[2], and values[3]. Note that the expression will only work if high is less than the total length of the list values.

Working With the End

  1. The program prints m.
  2. Python interprets a negative index as starting from the end (as opposed to starting from the beginning). The last element is -1.
  3. The last index that can safely be used with a list of N elements is element -N, which represents the first element.
  4. del values[-N] removes the first (zeroth) element from the list.
  5. values[:-1]

Slice Bounds

lithium
  1. First we assign the string lithium to the variable element. Which displays nothing.
  2. When we ask to print the slice lithium[0:20] Python returns lithium which is element[1:] and element[-1:20] which is just an empty slice, there is nothing else to display.
  3. When we ask to print element[-1:3] nothing is printed because the low value -1 is bigger, as an index than the high value 3. So the slice is empty