Some one explain this to me please | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Some one explain this to me please

What is the different between the two answers in This code . https://code.sololearn.com/ctgUqYg0a3xe/?ref=app

31st May 2020, 9:13 AM
Abdollahi Mohammed
Abdollahi Mohammed - avatar
7 Answers
+ 1
Abdollahi Mohammed python creates the same empty list and copies it n times(rows) in your 'ls'. To better understand what is happening, try changing a single element in 'ls', you will see it gets reflected in all rows. While in 'lst', they are n separate lists. Also, you can change n-1 in ur code to -1 For in depth explanation: refer python shallow copying and deep copying.
31st May 2020, 12:07 PM
fork()
fork() - avatar
+ 1
Thank you very much for your explanation
31st May 2020, 12:28 PM
Abdollahi Mohammed
Abdollahi Mohammed - avatar
0
This is a list not just printing
31st May 2020, 9:23 AM
Abdollahi Mohammed
Abdollahi Mohammed - avatar
0
I solve the problem but l didn't get why the two answers are different Read the question please
31st May 2020, 9:38 AM
Abdollahi Mohammed
Abdollahi Mohammed - avatar
0
Line 20 and 21
31st May 2020, 9:46 AM
Abdollahi Mohammed
Abdollahi Mohammed - avatar
0
Exactly but look at two answers
31st May 2020, 9:51 AM
Abdollahi Mohammed
Abdollahi Mohammed - avatar
0
I use the two list in same way But the output is different I just want to know why
31st May 2020, 10:00 AM
Abdollahi Mohammed
Abdollahi Mohammed - avatar