Если понял правильно:
from typing import Optional
def freq(arr: list, digit: int = 1) -> Optional[float]:
count = 1
res = []
for x in arr:
if x == digit:
res.append(count)
count = 0
count += 1
try:
return sum(res) / len(res)
except ZeroDivisionError:
return None
a = [0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
print(a, ' --> ', freq(a))
a = [0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0]
print(a, ' --> ', freq(a))
# [0, 0, 0, 0, 1, 0, 0, 0, 0, 1] --> 5.0
# [0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0] --> 3.142857142857143