So I have two lists and I want to use .pop() to remove an item from ListA and then use .append() to add it to ListB. I’ve tried this, but as soon as I use .pop(), the .append() function takes one index after that.
Here is the code I have so far:
ListA = ['a', 'b', 'c', 'd', 'e']
ListB = []
ListA.pop()
ListA.pop()
ListA.pop()
print 'ListA =', ListA
print 'ListB =', ListB
The output I get is:
ListA = ['a', 'b']
ListB = []
I would like the output to look like this:
ListA = ['a', 'b']
ListB = ['e', 'd', 'c']
I know I don’t have any .append() functions, but when I put them in there I get an error. So that’s the code working with just the .pop() function. I want to take the item that is being removed with .pop() and then append it to ListB.
Thanks for your help.
Pass the popped element to the append function: