enumerate()
returns a generator object; you only printed the representation of the object, then discard it again. The second line then reused the same memory location for a now object.
You can just refer directly to the temp_buffer
object without enumerate()
here:
for i, word in enumerate(temp_buffer):
print(temp_buffer[i])
print(temp_buffer[-1])
but temp_buffer[i]
is the same thing as word
in that loop. temp_buffer[-1]
is the last word in your list.
If you wanted to know how many more words there are to process, use len(temp_buffer) - i
, the length of the temp_buffer
list, subtracting the current position.