Python remove method error in ouput
#Write a function called attendance_check. attendance_check #should have two parameters: roster and present. Both roster #and present will be lists of strings. Return a list (sorted #alphabetically) of all strings in the list roster that are #not in the list present. In other words, if roster is a #list of students enrolled in a class and present is a list #of students in class today, return a list of students that #are absent. ************************************************************************************************ def attendance_check(roaster, present): for item in roaster: if item in present: roaster.remove(item) return roaster test_roster = ['Jessica', 'Nick', 'Winston', 'Schmidt', 'Cece', 'Ferguson'] test_present = ['Nick', 'Cece', 'Schmidt', 'Jessica'] print(attendance_check(test_roster, test_present)) ****************************************************************** my answer is ['Nick', 'Winston', 'Cece', 'Ferguson'] which is wrong But the answer should be: ******************************************************************* ['Ferguson', 'Winston'] ******************************************************************** I tried to debug this code and found out that every time I remove an item from the roaster, it is skipping the next item in the roaster and taking the item after that.. but I dont understand why.. Can anybody please explain why this is happening