Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 4. (Reverse) Implement the function reverse) in reverse.py that reverses

ID: 3698798 • Letter: P

Question

Problem 4. (Reverse) Implement the function reverse) in reverse.py that reverses the one-dimensional list a in place, ie, without creating a new list $ python3 reverse. py to be or not to be that is the question uestion the is that be to not or be to Linux Mint [Runningl reverse.py (/coursework/homework6) File Edit View Search Tools Documents Help import stdio import sys # Reverse the one-dimensional list a in place, ie, without creating a new list. ef reverse(a) # Iterate over half of the list a. Exchange element at 1 in a with the # element at len (a) -1-1. for i in # Test client [DO NOT EDIT]. Reads strings from standard input into a list, # reverses the list, and prints the reversed list def main): a = stdio. readAllSt rings() reverse (a) for v in a[:-1]: stdio.writef (.%s v) stdio.writeln (al-1 if name maln main()

Explanation / Answer

def reverse(arr):

    for i in range( 0 , int( len(arr) / 2 ) ):

   

        # swap the elements

        temp = arr[i]

        arr[i] = arr[ len(arr) - i - 1 ]

        arr[ len(arr) - i - 1 ] = temp

       

arr = [1, 2, 3, 4, 5]

reverse(arr)

print(arr)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote