Hello, can anybody please explain me, why the code is doing what he does? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Hello, can anybody please explain me, why the code is doing what he does?

Python array-problem when appending itself https://code.sololearn.com/cd6fn9ny1pPE/?ref=app

7th Mar 2019, 2:23 PM
Max M.
Max M. - avatar
7 Answers
7th Mar 2019, 2:48 PM
Seniru
Seniru - avatar
7th Mar 2019, 2:35 PM
Sudarshan Rai
Sudarshan Rai - avatar
+ 1
Sure, but it's returning [[...]] Imo, either it should be [[]], because it copies the value of the array, or it should return an error, because the value is a reference to itself, which would end up in an infinite loop. Or does the ... mean, that it contains vague values?
7th Mar 2019, 2:39 PM
Max M.
Max M. - avatar
+ 1
Hm, seems, that the "..." means, there is vague content. I wonder, if there is any useful reason to not return an error. Thank you for your answers
7th Mar 2019, 3:02 PM
Max M.
Max M. - avatar
0
You added array a into array a. If you set the array to [1, 2] instead, the output would be: [1, 2, [1, 2]]
8th Mar 2019, 1:48 PM
kritomas
kritomas - avatar
0
No, the output would be [1,2,[1,2,[1,2,[...]]]]. Python handles the problem by replacing the recursive array through "..." -> [1,2,[...]]
8th Mar 2019, 2:02 PM
Max M.
Max M. - avatar
0
len (a) shows 1 Maybe similar to normal appending same empty array is appended in it but only once. [...] Does this changes with more no. of element or not!!
30th Mar 2019, 3:34 PM
Ashok
Ashok - avatar