Python Challenges: Lists Advanced Number 4 Double Index

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]


    new_lst = front + lst[index+1:]

    return new_lst


    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.


Why are you using a loop?

the problem is with return, return does literally what is says: returning/handing back data to the function call. Which signals that the function is done executing (so the remaining iterations of your loop are not executed)

1 Like

I guess my thought process with the loop was iterating through the list and doing the same action to each index, which now that I’m working on the Loop Challenges seems like it wasn’t the best solution for the problem.