Home>
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.append(func_rand_num)
lst2.extend(lst1)
lst1[0]= lst1[0]() # we change lst1
We then expect lst2 to change...
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:14Well then, yes, you need to add a link to the list, not the list itself
CrazyElf2022-02-08 22:42:14Related questions
- Compare custom list and list of lists (comparing lists of different lengths) Python
- python : List index out of range error, don't know how to fix it [duplicate]
- TypeError: 'list' object is not callable. Literally today I started learning Python and telebot API and I don’t understand what
- python : How to add an element from list 1 to a dictionary in list 2?
- python : Why does list.remove() incorrectly remove elements in a loop?
- python : Sending a file using telegramAPI
- Program for finding synonyms of Russian words python
- javascript : How to pass value of js variables to python(eel)?
- python : How to create a window in the game for example (dota2)
.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