Skip to content

Instantly share code, notes, and snippets.

@richardpascual
Last active June 18, 2021 22:22
Show Gist options
  • Save richardpascual/40acf27f0dbed211288af99cc545a1ba to your computer and use it in GitHub Desktop.
Save richardpascual/40acf27f0dbed211288af99cc545a1ba to your computer and use it in GitHub Desktop.
Double the list value for the referenced index position.
#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))
@richardpascual
Copy link
Author

This came close but needed handling for index values larger than the original list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment