-3

I don't know why 'lllist' that I used as list is not changed as enter image description here'superman' list was changed.

2 Answers2

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.

esqew
  • 42,425
  • 27
  • 92
  • 132
amew646
  • 89
  • 4