Hello,
Could someone explain what I am doing wrong here? I thought it out logically and am stumped at my errors. Thank you!
Challenge:
Create a function named
double_index
that has two parameters: a list namedlst
and a single number namedindex
.The function should return a new list where all elements are the same as in
lst
except for the element atindex
. The element atindex
should be double the value of the element atindex
of the originallst
.If
index
is not a valid index, the function should return the original list.
Code:
#Write your function here
def double_index(lst, index):
if lst[index] > len(lst):
return lst
else:
replace = (lst[index] * 2)
new = lst[:lst[index]] + lst(replace) + lst[lst[index] + 1:]
return new
#Uncomment the line below when your function is done
print(double_index([3, 8, -10, 12], 2))
Error:
"TypeError: List object is not callable