[Tutor] Can someone please help me with this?

Anton Gilb antongilb at gmail.com
Wed Nov 6 04:10:20 CET 2013


Hi everyone, I'm a novice student struggling through my first python
course. Currently stuck on how to tackle this exercise. Any input would be
appreciated, and I know you guys can not just give me the answer, I'm just
looking for help to understand how to work through this.

This is the exercise:

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).

This is what I've come up with so far, it looks like garbage I know.

list1 = [1,2,3,4,5,6,7,8,9]
list2 = [100,200]
final_list2 = []

def transform(list1, list2, r1, r2):
        temp_list = list1[4:7:-1]
        final_list2 = list2.append(temp_list)


print(final_list2)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131105/6926775f/attachment-0001.html>


More information about the Tutor mailing list