Python 3 : Lists advanced code challenges

Forgive me if this is a stupid question but in question 4 in Python 3: Lists advanced code challenges where it has you double the value of a index, why is it that where it says new_list = new_list + lst[index+1:], that I can’t use new_list = new_list + lst[-1:]. It returns the new_list in the exact same way I was just given a message to "Double the value at position index in lst". I was just wondering if there’s any specific reason to use index+1 over -1. I figured if the list was bigger wouldn’t I want to use -1, wouldn’t it make it more scalable?

never mind I figured it out, -1 wouldn’t include any of the values in between index and the end of list. index+1 is the scalable version. lol forgive me XD

1 Like

Why do you use list slicing? To ensure the original list isn’t modified?

I would then simple do two steps:

copy the list
modify the new list:

new_list[index] *= 2

so much easier to read then all this slicing

thanks, I couldn’t figure out this problem so ended up looking at the solution and going through it step by step so I knew which each line did. but your right that makes it a lot easier and shorter too.

1 Like

Hi, new to coding, I intend to really understand functions and lists, however, these last two articles seems to be a little out of left field and I am wondering if there is anyone available to tutor through these articles?

Thank you,
Keith