+ 1

Pop function in Python

Why the output is [2,4]? https://code.sololearn.com/cVbTYKMSobfF/?ref=app I have one more question: https://code.sololearn.com/cnHvL392LB3D/#ref=app Why the output is [[1,0],[1,0]]? It needs to be [[1,0],[0,0]]?

17th Jun 2018, 9:44 PM
Yusuf
Yusuf - avatar
6 ответов
+ 3
first you remove the first element from the list: 1, 2, 3, 4, 5 -> 2, 3, 4, 5 then you remove the second element in that one: 2, 3, 4, 5 -> 2, 4, 5 finally you remove the third element from that one: 2, 4, 5 -> 2, 4 hope this helped
17th Jun 2018, 9:57 PM
hinanawi
hinanawi - avatar
+ 14
list = [1,2,3,4,5] list.pop(0) # pops 1, the list is now [2,3,4,5] list.pop(1) # pops 3, the list is now [2,4,5] list.pop(2) # pops 5, the list is now [2,4] print(list) # prints [2,4]
17th Jun 2018, 9:58 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
s = [[0]*2]*2 s[0][0] = 1 s[0][1] = 2 print(s) ids = [[id(x) for x in y] for y in s] print(ids) print(ids[0][0] == ids[1][0]) print(ids[0][1] == ids[1][1])
9th Jul 2018, 8:31 PM
Mert Yazıcı
Mert Yazıcı - avatar
0
New question added.
17th Jun 2018, 11:12 PM
Yusuf
Yusuf - avatar
0
Then what does it mean? Does it constructs the list when we assign something? Too different.
18th Jun 2018, 12:52 AM
Yusuf
Yusuf - avatar
0
Thanks for your doubt and those who answered... I learnt a new concept
18th Jun 2018, 6:13 AM
Sai Rohan Reddy
Sai Rohan Reddy - avatar