I don't know why 'lllist' that I used as list is not changed as enter image description here'superman' list was changed.
Asked
Active
Viewed 48 times
-3
-
1Please post your code as text instead of as images – 12944qwerty Jun 04 '21 at 00:59
-
1Does this answer your question? [How to modify list entries during for loop?](https://stackoverflow.com/questions/4081217/how-to-modify-list-entries-during-for-loop) – 12944qwerty Jun 04 '21 at 01:03
2 Answers
1
In the first loop you are getting a view of the list which performs some operation but the operations result isn't put back into the list.
Whereas in the second loop you are getting the whole object itself which you can manipulate to your requirement.

Anurag Dhadse
- 1,722
- 1
- 13
- 26
0
lllist is a list where its elements are of type int, whereas the elements of the list superman are lists themselves. So here is the catch: Lists are referenced and indexed by their addresses; hence when a list is updated anywhere in the variable's scope, the list will be updated. Lists in the superman are updated in the for loop (triple 0s were added), and we got our outputs reflecting this change.