Consider the following piece of code:
def func1(a): a[:] = [x**2 for x in a] a = range(10) print a #prints [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] func1(a[:5])
This will work:
a = range(10) a[:5] = [c**2 for c in a[:5]]