+ 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]]?
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
+ 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]
+ 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])
0
New question added.
0
Then what does it mean? Does it constructs the list when we assign something? Too different.
0
Thanks for your doubt and those who answered... I learnt a new concept