Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Question : -Implement following functions: 1. reverse_to_new_list(lst) - This function creates a new list containing the elements of lst in reverse order and returns

Python Question :

-Implement following functions:

1. reverse_to_new_list(lst) - This function creates a new list containing the elements of lst in reverse order and returns it.

2. reverse_in_place(lst)- When called, this function changes the order of the elements in lst (in place) to be in the reverse order.

Hint: think about the how the positions change before and after the reverse.

-Expect output:

After reverse_to_new_list, lst1 is [1, 2, 3, 4, 5, 6] and the returned list is [6, 5, 4, 3, 2, 1]

Before reverse_in_place, lst2 is [1, 2, 3, 4, 5, 6]

After reverse_in_place, lst2 is [6, 5, 4, 3, 2, 1]

-This is code:

def reverse_to_new_list(lst):

def reverse_in_place (lst):

def main (): lst1 = [1, 2, 3, 4, 5, 6] rev_lst1 = reverse_to_new_list (lst1) print ("After reverse_to_new_list, lst1 is", lst1, "and the returned list is", rev_lst1)

lst2 = [1, 2, 3, 4, 5, 6] print ("Before reverse_in_place, lst2 is", lst2) reverse_in_place (lst2) print("After reverse_in_place, lst2 is", lst2)

main ()

*I don't understand the difference between reverse to new list and reverse in place. Can you explain it with the code?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

7. How might you go about testing these assumptions?

Answered: 1 week ago