What is 'x[i] = x[i]' mean?

def my_function(x):
for i in range(0, len(x)):
x[i] = x[i]
return x

print my_function(range(1,3))

using indexes allows you to re-assign values in a list. for example:

the_list = ['a', 'b', 'c']
the_list[2] = 'd'

would assign d to index 2, so c gets updated to d

in your case x[i] = x[i] will re-assign the element at index i (determined by loop) with the current value at index i. So essential, nothing happens (just re-assigning the same value, bit pointless)

1 Like