From 085cc2cdac2492a4b4ee40dbeb7c636ccd205901 Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Thu, 10 Nov 2022 14:52:06 -0800 Subject: [PATCH] More utility functions --- foldingdiff/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/foldingdiff/utils.py b/foldingdiff/utils.py index 15b450d..77da838 100644 --- a/foldingdiff/utils.py +++ b/foldingdiff/utils.py @@ -51,6 +51,17 @@ def num_to_groups(num: int, divisor: int) -> List[int]: return arr +def seq_to_groups(seq:Sequence[Any], divisor:int) -> List[Sequence[Any]]: + """ + Generates a list of items of at most items + >>> seq_to_groups([1,2,3,4,5,6,7,8,9], 3) + [[1, 2, 3], [4, 5, 6], [7, 8, 9]] + >>> seq_to_groups([1,2,3,4,5,6,7,8,9], 4) + [[1, 2, 3, 4], [5, 6, 7, 8], [9]] + """ + return [seq[i:i+divisor] for i in range(0, len(seq), divisor)] + + def tolerant_comparison_check(values, cmp: Literal[">=", "<="], v): """ Compares values in a way that is tolerant of numerical precision