如何用list和相关函数解决问题

It is oftentimes advantageous to be able to transfer 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 simultaneously 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 as the following:

transform(list1, list2, 4,7).

请按功能描述实现transform函数,并设计合适的主程序调用该函数。

def transform(list1, list2, r1, r2):
    res = list2 + list1[r1:r2][::-1]
    list1[r1:r2] = []
    return res

list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
list2 = [100, 200]
r1 = 4
r2 = 7
r = transform(list1, list2, r1, r2)
print(list1, r)