[Tutor] Can someone please help me with this?

Alan Gauld alan.gauld at btinternet.com
Wed Nov 6 18:19:37 CET 2013


On 06/11/13 03:10, Anton Gilb wrote:

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

On the contrary its not too far away.
But we'd rather see a garbage first attempt than no attempt
at all, at least we then know where the problems lie!

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

You don't need the final_list here

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

But you should *return* this value here. This is creating a new local 
variable inside the function, it's not using the global value
you defined above. Also since append() (and extend() for that matter)
do not return a list value final_list2 will always equal None. You
are modifying list2 directly.

Others have commented on the other code inside the function.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list