So I have the following Python code, which appends numbers 1-10 to the list values:
values = []
for value in range(1, 11):
values.append(value)
print(values)
And, as expected, gives us [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].
Although impractical, just out of curiosity, I attempted to recreate this result using insert() instead of append():
values = []
for value in range(1, 11):
values.insert(-1, value)
print(values)
Which gave me the result [2, 3, 4, 5, 6, 7, 8, 9, 10, 1].
I tried this with other ranges as well, and the same thing happens every time: It is in ascending order, except for the smallest number being at the end.
From the Python Documentation Tutorial, I now know that a.insert(len(a), x) can be used to mimic a.append(x). However, I still do not understand why inserting the values to the last position in a list works except for the smallest value.