I tried this code for the following exercise
Link to code challenge
I want to know if there is a better method to exclude an item from the list using index?
def double_index(lst, index): valid_index = len(lst) - 1 # print (valid_index) # print (lst[index]) if (index <= valid_index) and (index >= 0): new_element = 2* lst[index] lst [index] = new_element return (lst) else: return (lst) #Uncomment the line below when your function is done print(double_index([3, 8, -10, 12], 0))
When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!
If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!