- #1
mr.me
- 49
- 0
This isn't quite homework, it was just in my textbook as an illustration. Below is a function to return a list in reverse order.
Why does it work? My brother tried to explain it to me but failed to clarify. The only line I don't understand is the third and what process takes place because of it.
Why does it work? My brother tried to explain it to me but failed to clarify. The only line I don't understand is the third and what process takes place because of it.
Code:
def list_reverse(a_list):
for index in range(len(a_list) / 2):
a_list[index],a_list[-index-1] = a_list[-index-1],a_list[index]
return a_list
this_list=["happy", 1,2,3,4,5]
print list_reverse(this_list)