diff options
| author | Scott Gasch <[email protected]> | 2021-09-28 23:27:51 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2021-09-28 23:27:51 -0700 |
| commit | 986d5f7ada15e56019518db43d07b76f94468e1a (patch) | |
| tree | ac3460a13667ac3dc8aa1e84c6b4fc8cfee648dc /list_utils.py | |
| parent | 0bc6e4312cad0f997751739e750954ac39dfa6cc (diff) | |
Various changes
Diffstat (limited to 'list_utils.py')
| -rw-r--r-- | list_utils.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/list_utils.py b/list_utils.py index c04a534..182e2bc 100644 --- a/list_utils.py +++ b/list_utils.py @@ -2,7 +2,7 @@ from collections import Counter from itertools import islice -from typing import Any, Iterator, List, Mapping +from typing import Any, Iterator, List, Mapping, Sequence def shard(lst: List[Any], size: int) -> Iterator[Any]: @@ -97,6 +97,19 @@ def dedup_list(lst: List[Any]) -> List[Any]: return list(set(lst)) +def uniq(lst: List[Any]) -> List[Any]: + """ + Alias for dedup_list. + + """ + return dedup_list(lst) + + +def ngrams(lst: Sequence[Any], n): + for i in range(len(lst) - n + 1): + yield lst[i:i + n] + + if __name__ == '__main__': import doctest doctest.testmod() |
