refactoring

This commit is contained in:
Devaev Maxim
2020-09-10 07:30:25 +03:00
parent a6385cd20e
commit 967afb2d9a
5 changed files with 25 additions and 11 deletions

View File

@@ -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))