Output is in reverse order. Why?

Hello guys!

I have a question about output of this exercise:

Why is output of this exercise in reverse order?

This is the output:
[‘Loki’, ‘Arius’, ‘Obie’, ‘Alexa’, ‘Minerva’, ‘Dora’]

I did it right but I’m curious about.

You could use print statements, to see what your code does

you could go over the different lines of code, and try to visualize the flow. pop will remove the last item ( Loki), and append it (add it to the end of the students_in_poetry list), then the next iteration of the loop, the last item is removed from all students (which is now Arius), and gets appended to the other list

this is what is causing the reverse

or you could use a “debug tool” to step through the code, here is an online one:

http://www.pythontutor.com/visualize.html

4 Likes