diff options
Diffstat (limited to 'string_utils.py')
| -rw-r--r-- | string_utils.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/string_utils.py b/string_utils.py index b3019cf..78e72cc 100644 --- a/string_utils.py +++ b/string_utils.py @@ -10,7 +10,7 @@ import numbers import random import re import string -from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple +from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple import unicodedata from uuid import uuid4 @@ -1285,10 +1285,13 @@ def ngrams(txt: str, n: int): """ words = txt.split() for ngram in ngrams_presplit(words, n): - return ' '.join(ngram) + ret = '' + for word in ngram: + ret += f'{word} ' + yield ret.strip() -def ngrams_presplit(words: Iterable[str], n: int): +def ngrams_presplit(words: Sequence[str], n: int): return list_utils.ngrams(words, n) |
