I know that my question is most likely incorrectly formulated, but I could not express it in another way:

There are two lists: lst1, lst2. In lst2, we store lst1 with the .extend() method. And then change lst1.

The goal is to ensure that when lst1 changes, those changes are immediately transferred to lst2. How can this be implemented?

Here is a sample code:

lst1= []
lst2= [2, 5]
lst1[0]= lst1[0]() # we change lst1

We then expect lst2 to change...

.extend() adds a copy. .append(lst1) will add a link. When changing in lst1, the corresponding element of lst2 will also change (but apparently this is not what you are interested in)

avp2022-02-08 22:42:14

You better formulate the original problem. Why are you trying to achieve this behavior? If out of interest -this is one thing, if for some practical purposes -this is another. Maybe it needs to be dealt with differently.

CrazyElf2022-02-08 22:42:14

@CrazyElf just out of curiosity.

Ratmir2022-02-08 22:42:14

Well then, yes, you need to add a link to the list, not the list itself

CrazyElf2022-02-08 22:42:14