Last active
June 18, 2021 22:22
-
-
Save richardpascual/40acf27f0dbed211288af99cc545a1ba to your computer and use it in GitHub Desktop.
Double the list value for the referenced index position.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Write your function here | |
def double_index(lst, index): | |
if index >= len(lst): | |
return lst | |
newlst = lst[0:index] | |
newlst.append(lst[index]*2) | |
return newlst + lst[index+1:] | |
#Uncomment the line below when your function is done | |
print(double_index([3, 8, -10, 12], 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This came close but needed handling for index values larger than the original list.