Taking a look at the cpython
code on GitHub, we can get some intuition as to why it no longer works.
The iterator that is returned essentially requires knowing the position of the last index and the length of the array. If the size of the array is changed, the iterator will no longer work.
Test 1: Increasing the array length
This will not produce the correct results either, but the iterator does run:
s = [1,2,3]
t = reversed(s)
s.append(4)
for i in t:
print(i)
# output: [3, 2, 1]
Test 2: Decreasing, then increasing the length
s = [1,2,3]
t = reversed(s)
s.pop()
s.append(4)
for i in t:
print(i)
# output: [4, 2, 1]
It still works!
So there’s an internal check to see whether or not the last index is still valid, and if it is, it’s a simple for loop down to index 0.
If it doesn’t work, the iterator returns empty.