I appreciate that using .pop() in a for loop is not the way to go , I just wanted to understand why it creates the output it does.
I’ve understood everything in the Python3 course so far, but this one has been a bit difficult to get my head around to be honest!
I think I get it though.
The for loop goes through the cycle of iterating through indices [0], [1], [2] and [3] then it is outside the list and can’t continue.
When the .pop() action takes place, the list becomes something new, but the for loop continues to cycle through [0], [1], [2] and [3] as the list keeps changing.
list = [4, 5, 6, 7, 8, 9]
#ins= 0, 1, 2, 3, 4, 5
for loop cycle is for index 0 (4)
list[0] is popped (4)
list = [5, 6, 7, 8, 9]
#ins= 0, 1, 2, 3, 4
for loop cycle is for index 1 (6)
list[0] is popped (5)
list = [6, 7, 8, 9]
#ins= 0, 1, 2, 3
for loop cycle is for index 2 (8)
list[0] is popped (6)
list = [7, 8, 9]
#ins= 0, 1, 2
for loop cycle can’t continue because there is no index 3
Thanks for helping me to understand this mtf and stetim94!