py.lib.aw_web_tools
2024-02-25
py.lib.aw_web_tools/src/aw_web_tools/misc_tools.py
..init
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/aw_web_tools/misc_tools.py Sun Feb 25 15:18:36 2024 +0300 1.3 @@ -0,0 +1,9 @@ 1.4 +# coding: utf-8 1.5 +from typing import Union, List, Tuple 1.6 + 1.7 + 1.8 +def dict_filter(data: dict, need_keys: Union[List[str], Tuple[str]]) -> dict: 1.9 + """\ 1.10 + Создать новый словарь на основе существующего, добавив в него только нужные ключи 1.11 + """ 1.12 + return dict((key, val) for key, val in data.items() if key in need_keys) 1.13 \ No newline at end of file