Why do I get an index error?

Hello everyone!

please explain why this code below makes an ‘IndexError: pop from empty list’ ? thanks in advance

all_students = [“Alex”, “Briana”, “Cheri”, “Daniele”, “Dora”, “Minerva”, “Alexa”, “Obie”, “Arius”, “Loki”]
students_in_poetry =
i = len(students_in_poetry)
while i < 6:
student = all_students.pop()


maybe insert print statement to see the problem?

purely looking at the code, it seems you have an infinity loop (the loop condition will never be false), thus it will pop all the students from all_students, so then the list is empty, and it will still attempt a pop, which results in the IndexError you described