creating a reverse method for a python list from scratch

I want to create a reverse method for a list. I know there already is such a method built into python but I want to try it from scratch. Here's what I have and it seems to make sense to me but it just returns the list in the same order. My understanding was that lists are mutable and I could just reassign values in the loop.

def reverse(data_list):
    length = len(data_list)
    s = length

    for item in data_list:
        s = s - 1
        data_list[s] = item
    return data_list
5
задан 9 March 2011 в 17:01
поделиться