Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slice per-rule/ list by picking every N-th rule from list #164

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions per-rule/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,12 @@
from conf import partitions


def slice_list(full_list, divident, divisor):
def slice_list(full_list, start, modulus):
"""
Slice a 'full_list' into approx. equally-sized 'divisor' parts,
return the 'divident' slice.
Slice a 'full_list' into approx. equally-sized parts, created from
every N-th ('modulus') item from 'start' - 1 (index 0) position.
"""
total = len(full_list)
quotient = int(total / divisor)
remainder = total % divisor
# add 1 to the first dividents, up until all the added 1s
# are consumed (they add up to a value equal to remainder)
count = quotient + (1 if remainder >= divident else 0)
# starting index, from 0, with remainder gradually added,
# capped by max remainder value
start = (divident-1)*quotient + min(remainder, (divident-1))
# end = start of current slice + amount
# (as last valid index + 1, for python slice end)
end = start + count
# return a slice of the original list rather than copying it
return full_list[start:end]
return full_list[start-1::modulus]


def between_strings(full_text, before, after):
Expand Down