I have a file with a lot of numbers:
0.98
0.23
0.10
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
10.3
11.9
0.56
...
I want to print the number of line where the number 0 is repeated 10 consecutive times (as minimum). Consdering the above input, the output will be: 4 (for the line number 4 and because 0 es repeated 10 consecutive times). The files list.txt is a huge file. I'm new in Python. How can I do delete the error in the follow script:
import ast
values = open("list.txt","r")
values = list(map(int, ast.literal_eval(values.read().strip())))
count=0
length=""
if len(values)>1:
for i in range(1,len(values)):
if values[i-1]==values[i]:
count+=1
else :
length += values[i-1]+" repeats "+str(count)+", "
count=1
length += ("and "+values[i]+" repeats "+str(count))
else:
i=0
length += ("and "+values[i]+" repeats "+str(count))
print (length)