Modifying each element in a list in a function
Traceback (most recent call last):
File "python", line 8, in
File "python", line 5, in double_list
IndexError: list index out of range
Why does this not work correctly? Why does the x need to be range(0, len(x))? This method works fine for printing every element in the list but when changing every element like this it doesn't work?
n = [3, 5, 7] def double_list(x): for i in x: x[i] = x[i] * 2 # Don't forget to return your new list! return x print double_list(n)