Hello all, I was working on the Advanced Lists Python Code Challenge and ran into a bit of a roadblock that I’d like some help with.
The link to the challenge is below:
Codecademy Python Challenge Advanced Lists
Here is my solution:
#Write your function here
def double_index(lst, index):
for index in range(0, (len(lst)-1)):
front = lst[:index]
front.append(lst[index]*2)
new_lst = front + lst[index+1:]
return new_lst
else:
return lst
#Uncomment the line below when your function is done
print(double_index([3, 8, 10, 12], 2))
When I run my program, for some reason it keeps doubling only the item at index 0 rather than the item at the identified index.
After looking at a few of the solutions other people came to, I realize that I went about the challenge sort of backwards, but am still interested in figuring out why I can’t seem to pinpoint which index to double.
Thanks!