Some binary tree methods to support the unscramble progam's sparsefile
[python_utils.git] / string_utils.py
index b3019cfbbf70097a30e40fab70888701b02eb71c..78e72cca5a36e672fdc8931cf9a9b9b946ac148e 100644 (file)
@@ -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)