diff options
Diffstat (limited to 'kvmd/tools.py')
-rw-r--r-- | kvmd/tools.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/kvmd/tools.py b/kvmd/tools.py index 1259893c..6d10e227 100644 --- a/kvmd/tools.py +++ b/kvmd/tools.py @@ -20,10 +20,14 @@ # ========================================================================== # +import operator import functools +from typing import Tuple +from typing import List from typing import Dict from typing import Hashable +from typing import TypeVar # ===== @@ -41,3 +45,11 @@ def rget(dct: Dict, *keys: Hashable) -> Dict: if not isinstance(result, dict): raise TypeError(f"Not a dict as result: {result!r} from {dct!r} at {list(keys)}") return result + + +_DictKeyT = TypeVar("_DictKeyT") +_DictValueT = TypeVar("_DictValueT") + + +def sorted_kvs(dct: Dict[_DictKeyT, _DictValueT]) -> List[Tuple[_DictKeyT, _DictValueT]]: + return sorted(dct.items(), key=operator.itemgetter(0)) |