+ 1

What's the logic behind this guys

I really don't understand the logic behind this, could someone explain this to me https://code.sololearn.com/cu6H2dd1xTI9/?ref=app

2nd Nov 2021, 7:36 PM
A Mohammed Alhaan
A Mohammed Alhaan - avatar
2 ответов
+ 6
a = [[]]*3 a[0].append(3) print(a) 1. 3 multiplies the empty lists inside the 2d 3 times this it will look like this. [[],[],[]] 2. Then you want to append the 3 at the index 0 of each list in the 2d list. And it will be. [[3],[3],[3]]
2nd Nov 2021, 8:31 PM
MATOVU CALEB
MATOVU CALEB - avatar
+ 2
Thank you so much bro
2nd Nov 2021, 8:49 PM
A Mohammed Alhaan
A Mohammed Alhaan - avatar