I don’t see it as something useful for production, but supposing it’s just an exercise, let’s go.
def copia_lista(dest, orig):
''' (list, list) -> None'''
dest = orig.copy()
When you do this you’re basically creating an object dest
new, in the local scope of the function, which in this scope will overwrite the object dest
received as parameter. When the function finishes executing, the local scope is terminated and the object dest
that you created is lost, keeping unchanged the dest
original.
As list is a changeable type, just change the object without making a new assignment.
def copia_lista(dest, orig):
''' (list, list) -> None'''
dest.clear() # Remove os elementos de dest
for item in orig:
dest.append(item)
In this way,
>>> a = [8, 9]
>>> b = [1, 2, 3, 4]
>>> copia_lista(a, b)
>>> a
[1, 2, 3, 4]
>>> b
[1, 2, 3, 4]
A simpler way to execute the same logic would be:
def copia_lista(dest, orig):
''' (list, list) -> None'''
dest[:] = orig
Producing the same result.
This is not exactly the solution previously presented in this answer?
– Woss