Nov-05-2019, 09:14 PM
Lists are mutable. So if you reassign one, it doesn't reassign the whole list, it doesn't make a copy of one. You just now have two names pointing to the same list. And if you make a list of lists (if you're not careful), you end up with a list of references to the same list.
So the first two lists you have, a1 and a2, and just a bunch of references to the same list that tt is pointing at. If you change any one of them, that changes the list they are all pointing at. Now you can look at any of them, and they are all pointing at the original list which you changed.
a3 is similar, in that it's one list. The multiplication just makes more references to that same list. It's a different list than tt, but a3 is still four things pointing to the same list.
b1 is different because each time through the loop in the list comprehension, the list is reevaluated. So it is four pointers to four different lists. They are still pointers, though. So if you assigned cc = b[0], and changed cc, b[0] would also reflect those changes.
So the first two lists you have, a1 and a2, and just a bunch of references to the same list that tt is pointing at. If you change any one of them, that changes the list they are all pointing at. Now you can look at any of them, and they are all pointing at the original list which you changed.
a3 is similar, in that it's one list. The multiplication just makes more references to that same list. It's a different list than tt, but a3 is still four things pointing to the same list.
b1 is different because each time through the loop in the list comprehension, the list is reevaluated. So it is four pointers to four different lists. They are still pointers, though. So if you assigned cc = b[0], and changed cc, b[0] would also reflect those changes.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures