Sep-30-2018, 04:28 PM
Quote:Because my brain doesn't retain things as it did in 1987You're too young for this! Need to go on Gluten Free Diet. I will vouch for it, 70+ YO.
Quote:and the wider "how to learn python" questionTrying things like you're doing now is good.
I recommend this tutorial (my favorite): https://www.python-course.eu/python3_course.php
i also recommend installing VSCode (Not Visual Studio, unrelated to MS) with it you can run the debugger, and
watch the guests list expand and contract as you execute step by step.
Output:guests = ['David', 'Adolf','Charles']
Guests: ['David', 'Adolf','Charles']
guests.insert(0, 'Geoff')
Guests: ['Geoff', 'David', 'Adolf','Charles']
guests.insert(1, 'Colin')
Guests: ['Geoff', 'Colin', 'David', 'Adolf', 'Charles']
guests.append('Fred')
Guests: ['Geoff', 'Colin', 'David', 'Adolf', 'Charles', 'Fred']
there are 6 items in the list
Iteration 1:
for guest in guests: # Here's the problem, see below
popped=guests.pop()
['Geoff', 'Colin', 'David', 'Adolf', 'Charles']
last popped value - Fred
The problem is that you are using the contents of the list to control the iterations.The contents is a moving target so soesn't perform as you expect.
If you want to xcontinue until the list is empty, instead of loop, use:
while guests: popped=guests.pop() removedlist.append(popped) ...