If the values in the list are same then your code will remove 1 element which will reduce the length of the list. But the for loop started with a fixed length of the list. As a result you will get "list index out of range exception"
so say you have 100 100 4 5
length = 4 and valid index (0 to 3)
when an element is removed say 100, then list length will become 3 and trying to access index 3 will cause an exception.