Could someone explain to me how this python loop outputs the reverse order of elements in a list? This was part of a school assignment and I can't quite comprehend how this works.
I know this is a more difficult way of obtaining the reverse order of a list, but we were not allowed to use the reverse function and I could not seem to get list splicing to pass the autograder.
def reverse_list(stuff):
'''Function that reverses the order of elements in a list'''
i = 0
n = len(stuff)-1
while i<n:
temp = stuff[i]
stuff[i] = stuff[n]
stuff[n] = temp
i+=1
n-=1
#test
stuff = [1,2,3,4]
reverse_list(stuff)
print(list) #Output [4,3,2,1]
tempisn't necessary;stuff[i], stuff[n] = stuff[n], stuff[i].