выдает ошибку IndexError: list index out of range count = 1 i = int() pcount = 1 for i in range(len(lst2)-1): if lst2[i] == lst2[i+1]: while lst2[i] == lst2[i+1]: pcount+=1 i+=1 else: if pcount > count : count = pcount pcount = 1 - nothing in the code in question is system dependent. Make a minimal but complete example of the code that demonstrates the problem. Specify versions of Python on Windows and Linux. Give a full traceback. The minimum reproducible example is jfs
|
2 answers
In this part of the code:
while lst2[i] == lst2[i+1]: pcount+=1 i+=1 You do not have a check that the index i will not go beyond the lst2 array. Actually, when i takes the index of the last element, lst2[i+1] will not exist
|
Perhaps in a while loop, you go beyond the bounds, since the loop itself goes to the last element regardless of for.
|