diff options
| author | Scott Gasch <[email protected]> | 2021-10-19 16:40:34 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2021-10-19 16:40:34 -0700 |
| commit | 351e77c767c9084aa486eedbdc9902c635b06261 (patch) | |
| tree | b41e328293b8f89ea8f56f02e451ea2afe7c2e2e /list_utils.py | |
| parent | 9484900f080e16f118806fe54973e69d36b043e8 (diff) | |
Bugfixes.
Diffstat (limited to 'list_utils.py')
| -rw-r--r-- | list_utils.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/list_utils.py b/list_utils.py index 182e2bc..a8030e3 100644 --- a/list_utils.py +++ b/list_utils.py @@ -100,12 +100,35 @@ def dedup_list(lst: List[Any]) -> List[Any]: def uniq(lst: List[Any]) -> List[Any]: """ Alias for dedup_list. - """ return dedup_list(lst) def ngrams(lst: Sequence[Any], n): + """ + Return the ngrams in the sequence. + + >>> seq = 'encyclopedia' + >>> for _ in ngrams(seq, 3): + ... _ + 'enc' + 'ncy' + 'cyc' + 'ycl' + 'clo' + 'lop' + 'ope' + 'ped' + 'edi' + 'dia' + + >>> seq = ['this', 'is', 'an', 'awesome', 'test'] + >>> for _ in ngrams(seq, 3): + ... _ + ['this', 'is', 'an'] + ['is', 'an', 'awesome'] + ['an', 'awesome', 'test'] + """ for i in range(len(lst) - n + 1): yield lst[i:i + n] |
