0
I don't understand for what you should use: [[]]*3
inner_lists = [[]] * 3 inner_lists[0].append(7) inner_lists[0].append(3) inner_lists[1][0] = 4 print(inner_lists) # The result is: [[4, 3], [4, 3], [4, 3]]
8 Answers
+ 4
well I thought about it a while...
and I must say: I agree
redundant Information.
+ 4
ha wow ... wait a moment....
deep in my mind there is a light going on...
linear algebra/standard matrices/
linear transformation.
these are matrices with many equal rows
the algorithms use them as read only.
+ 4
coooool ! so we got it!
@Maksim it was a pleasure for me to discuss with you!
thats what i hoped sololearn can do!
+ 3
In this case it is a demo for showing that you actually work on exactly one list, which has two clones (not copies)
+ 1
Frankly speaking, I think that case is absolutely useless, but I found a few of questions (that use the construction) among the questions of competition (battle-puzzles).
+ 1
Oma Falk! You are absolutely right! I found an article about it on the StackOverflow:
https://stackoverflow.com/questions/1550130/cloning-row-or-column-vectors
+ 1
Thank you very much! It was a pleasure for me, too! I really appretiate your help! :-)
0
Oma Falk! Thank you for the answer.
Are you sure that we can use the term "clone" in that case? The example is mine. I changed the element[1][0] of the list and all inner lists were affected. So, it means that we have only one inner list and three references to it. I'm not sure that the could describe it as three clones, because a cloned object lived independantly from its source.
I really don't understand the practical meaning of the construction. Why one needs to create a number of references to one inner list into the outer list?