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

It is often adventageous to be able to transfere data between multiple lists whi

ID: 3545795 • Letter: I

Question

It is often adventageous to be able to transfere data between multiple lists while rearranging their order. For instance, say that list1 = [1,2,3,4,5,6,7,8,9] and you wish to add the numbers in the index range 4:7 of list1 to another list, list2, in reverse order while simulataneously removing them from list1. If list2 = [100,200], the result will be list2 = [100,200,7,6,5]. Write a function named transform that takes as arguments list1, list2, r1, and r2, that removes items from list1 in the slice r1:r2, appends them onto list2 in reverse order, and returns the resulting list. For example, in this case, the function call will be transform(list1, list2, 4,7).

Explanation / Answer

please rate


def transform(l1,l2,r1,r2):
    while r2 > r1 :
        l2.append(l1[r2-1])
        l1.remove(r2)
        r2 = r2 - 1




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