+ 4
Would you like to share some ideas about this questions in briefly? I don't understand.
my_list = [3,5,6,7,8,1] for i in range(3): my_list.pop(i) print(my_list) # [5, 7, 1]
3 Réponses
+ 12
At the first step of the cycle, you delete 3. At the second passage of cycle, the list 3 is no longer in the list and 0 the position has already been passed, and it turns out that we delete 6. At the third passage of the cycle, the list no longer has 3 and 6, and we are at 2 positions in the list and therefore delete 8
+ 3
Rudy
my_list=[3,5,6,7,8,1]
for I in range(3):. #index 0,1and2
my_list.pop(i). # 3 will delete
Then after pop the new list will be [5,6,7,8,1] and i=1
Therefore At index 1 i.e., 6 will be pop
Then the value of i=2 i.e., 8 will pop
So ,
print(my_list) will be [5,7,1]
+ 3
Thanks I got it.