I’ve asked almost this just before now, but the fix doesn’t work for x = [[]], which I’m guessing is because it is a nested list, which is what I will be working with.
def myfunc(w):
y = w[:]
y[0].append('What do I need to do to get this to work here?')
y[0].append('When I search for the manual, I get pointed to python.org, but I can\'t find the answer there.')
return y
x = [[]]
z = myfunc(x)
print(x)
Here’s how you could fix your problem:
The thing about [:] is that it’s a shallow copy. You could also import deepcopy from the copy module to achieve the correct result.