it seems better to extract the index (or snapshot) extracting logic as one function and then feed the results to the loop detecting the above/below cutoff

    def find_expired_data(indices, time_unit, unit_count, separator='.', ...):
        ...