pydsa.combo¶
Index-combination helpers preloaded by sitecustomize: every pair and every triple of indices below n, in lexicographic order, without recursion; every substring of a sequence, in one of three orders.
pairs ¶
pairs(
n: int, type: Maker = tuple, back: bool = False
) -> Iterator[Any]
Every (i, j) with 0 <= i < j < n, in lexicographic order.
With back, the pairs are grouped by the later index instead: for each j in turn, every (i, j) with i < j. That is the dp order, where cell j looks back at every earlier cell.
Each pair is built by type: tuple by default, list for a LeetCode answer.
Source code in pydsa/combo.mu
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
triples ¶
triples(n: int, type: Maker = tuple) -> Iterator[Any]
Every (i, j, k) with 0 <= i < j < k < n, in lexicographic order.
Each triple is built by type: tuple by default, list for a LeetCode answer.
Source code in pydsa/combo.mu
27 28 29 30 31 32 33 34 35 | |
31 32 33 34 35 36 37 38 39 | |
substrings ¶
substrings(s: Sequence, by: str = 'start') -> Iterator
Every slice s[i:j] with 0 <= i < j <= len(s), each position once.
by picks the order: "start" groups the slices by where they start, shortest first; "end" groups them by where they end, longest first; "length" gives every slice of length 1, then of length 2, and so on, left to right. A list gives its subarrays the same way.
Source code in pydsa/combo.mu
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |