diff options
| author | Scott Gasch <[email protected]> | 2021-09-07 22:20:40 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2021-09-07 22:20:40 -0700 |
| commit | b10d30a46e601c9ee1f843241f2d69a1f90f7a94 (patch) | |
| tree | 30c95e6f4333b57ff3ae7a4dee278b2097612d10 /string_utils.py | |
| parent | f49bb9db0c6d1a8622dca1717db68462a4209112 (diff) | |
Various changes.
Diffstat (limited to 'string_utils.py')
| -rw-r--r-- | string_utils.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/string_utils.py b/string_utils.py index 45cf5aa..bca2b70 100644 --- a/string_utils.py +++ b/string_utils.py @@ -9,7 +9,7 @@ import logging import random import re import string -from typing import Any, Callable, Iterable, List, Optional +from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple import unicodedata from uuid import uuid4 @@ -981,3 +981,37 @@ def bigrams(txt: str): def trigrams(txt: str): return ngrams(txt, 3) + + +def shuffle_columns( + txt: Iterable[str], + specs: Iterable[Iterable[int]], + delim='' +) -> Iterable[str]: + out = [] + for spec in specs: + chunk = '' + for n in spec: + chunk = chunk + delim + txt[n] + chunk = chunk.strip(delim) + out.append(chunk) + return out + + +def shuffle_columns_into_dict( + txt: Iterable[str], + specs: Iterable[Tuple[str, Iterable[int]]], + delim='' +) -> Dict[str, str]: + out = {} + for spec in specs: + chunk = '' + for n in spec[1]: + chunk = chunk + delim + txt[n] + chunk = chunk.strip(delim) + out[spec[0]] = chunk + return out + + +def interpolate_using_dict(txt: str, values: Dict[str, str]) -> str: + return sprintf(txt.format(**values), end='') |
