diff options
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() |
