So I wrote a code that checks how much times in a list is the same number repeating in a row and when it gets that it divides them with a user inputted number and then sums all the numbers in a list. It all works until I got to the larger numbers then it just started not counting the last few numbers.
N = int(input())
Ai = input()
arr = [int(x) for x in Ai.split()]
c = 0
final = []
final2 = []
d = []
b = len(set(arr))
frozen_num = arr[0]
for i in range(0, len(arr) + b):
try:
if frozen_num == arr[0]:
arr.remove(arr[0])
c+=1
else:
final.append(c)
frozen_num = arr[0]
c = 0
except:
pass
final.append(c)
for l in final:
d.append(l/N)
final2 = map(int, d)
print(sum(final2))
Input: User chosen dividing number: "3", List of number ["5, 5, 5, 5, 4, 4, 4, 2, 2]
Output: 2
But when I gave it an input: 20 38 66 66 66 66 66 66 66 66 13 13 13 13 13 13 13 13 13 13 13 43 43 43 43 43 43 22 22 22 98 98 98 98 98 98 77 7 7 7 7 7 7 7 7 7 7 7 82 82 82 82 26 47 41 38 38 38 57 57 57 79 79 79 79 79 79 79 79 79 79 79 79 79 79 98 98 98 98 98 98 98 98 13 67 67 67 67 80 80 80 80 80 50 50 50 50 50 50 50
It gave me an output: 25 and not 26.
Because it didn't count the last few numbers correctly.
It would be a lot of help if someone could explain this behavior.