Skip to content

Commit

Permalink
chore: remove_dict_emptyで特定のkeyをignoreできるように
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Dec 3, 2023
1 parent 10c8c8d commit c2cac8f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mipac/utils/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,27 @@ def remove_list_empty(data: list[Any]) -> list[Any]:
return [k for k in data if k]


def remove_dict_empty(data: dict[str, Any]) -> dict[str, Any]:
def remove_dict_empty(
data: dict[str, Any], ignore_keys: list[str] | None = None
) -> dict[str, Any]:
"""
Parameters
----------
data: dict
空のkeyを削除したいdict
ignore_keys: list
削除したくないkeyのリスト
Returns
-------
_data: dict
空のkeyがなくなったdict
"""
_data = {}
_data = {k: v for k, v in data.items() if v is not None}
if ignore_keys is None:
ignore_keys = []
_data = {k: v for k, v in data.items() if v is not None or k in ignore_keys}
return _data
return _data


Expand Down

0 comments on commit c2cac8f

Please sign in to comment.