0
List Index out of range
I am trying to remove an element from a list, if the element appears more than 1 time in the list. But when I start my programm, I get an error: list index out of range. Can somebody please tell me, why I am getting this error? My code: zahlen=[1,2,5,2,2,6] a=len(zahlen) for i in range(a): element=zahlen[i] aE=zahlen.count(element) if aE>1: zahlen.remove(element) else: continue print(zahlen)
0 Antworten