Hackbright Code Challenges

Reverse List in Place

Reverse List in Place

Whiteboard

Easier

Concepts

Loops, Lists

Download

rev-list-in-place.zip

Solution

Reverse List in Place: Solution


Reverse a list in-place. Remember, for this to be “in-place” it can only use a small, constant amount of extra storage space, so no duplicating the list!

For example:

>>> lst = [1, 2, 3]
>>> rev_list_in_place(lst)
>>> lst
[3, 2, 1]

We’ve provided a file, revlistinplace.py, and a placeholder function, rev_list_in_place.

def rev_list_in_place(lst):
    """Reverse list in place.

    You cannot do this with reversed(), .reverse(), or list slice
    assignment!
    """

Implement rev_list_in_place.