Dorota Parzych5,706 Points
pop() - what was this function exactly doing?
I forgot what the pop() function was doing and why it influences our display_wishlist function Thanks in advance
adrian miranda13,529 Points
When you call pop() on a list, it gives you the last element on the list. However, it also modifies the list, actually removing the last element.
Or if you call pop(0) on a list, it removes the first element (the zeroth element) from the list. So again, it both gives you the first element, and removes it from the list.
In display_wishlist they use pop(0) to remove the first element, and print it with some fancy formatting. Later they go through and print everything in the list, but they don't wind up printing the first element again, because it was removed by the call to pop(0).
Dan B6,151 Points
Good question, I had the same one. The reason it wasn't used because pop edits the list as the teacher showed. He did this deliberately to show how easy it is to accidentally change a list. You should definitely use
If you don't want to edit the list like the pop function does.