def compact_zero_runs(iterable, max_zeros):
    zeros = 0
for i in iterable:
    if i == 0:
        zeros += 1
if zeros <= max_zeros:
    yield i
else:
    zeros = 0
yield i
How can I delete all zeros except for x of them in every run of consecutive zeros within a list?